# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
444315 |
2021-07-13T15:17:46 Z |
arwaeystoamneg |
Gap (APIO16_gap) |
C++17 |
|
76 ms |
2652 KB |
// EXPLOSION!
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
#include<chrono>
using namespace std;
typedef pair<int, int> pii;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pair<int, int>> vpi;
typedef vector<pair<ll, ll>> vpll;
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)
#define trav(a,x) for (auto& a: x)
#define pb push_back
#define mp make_pair
#define rsz resize
#define sz(x) int(x.size())
#define all(x) x.begin(),x.end()
#define f first
#define s second
#define cont continue
#define endl '\n'
//#define ednl '\n'
#define test int testc;cin>>testc;while(testc--)
#define pr(a, b) trav(x,a)cerr << x << b; cerr << endl;
#define message cout << "Hello World" << endl;
const int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 }; // for every grid problem!!
const ll linf = 4000000000000000000LL;
const ll inf = 1000000007;//998244353
void pv(vi a) { trav(x, a)cout << x << " "; cout << endl; }void pv(vll a) { trav(x, a)cout << x << " "; cout << endl; }void pv(vector<vi>a) {
F0R(i, sz(a)) { cout << i << endl; pv(a[i]); cout << endl; }
}void pv(vector<vll>a) { F0R(i, sz(a)) { cout << i << endl; pv(a[i]); }cout << endl; }void pv(vector<string>a) { trav(x, a)cout << x << endl; cout << endl; }
void setIO(string s) {
ios_base::sync_with_stdio(0); cin.tie(0);
#ifdef arwaeystoamneg
if (sz(s))
{
freopen((s + ".in").c_str(), "r", stdin);
if (s != "test1")
freopen((s + ".out").c_str(), "w", stdout);
}
#endif
}
#ifndef arwaeystoamneg
#include "gap.h"
#endif
#ifdef arwaeystoamneg
static void my_assert(int k) { if (!k) exit(1); }
static int subtask_num, N;
static long long A[100001];
static long long call_count;
void MinMax(long long s, long long t, long long* mn, long long* mx)
{
int lo = 1, hi = N, left = N + 1, right = 0;
my_assert(s <= t && mn != NULL && mx != NULL);
while (lo <= hi) {
int mid = (lo + hi) >> 1;
if (A[mid] >= s) hi = mid - 1, left = mid;
else lo = mid + 1;
}
lo = 1, hi = N;
while (lo <= hi) {
int mid = (lo + hi) >> 1;
if (A[mid] <= t) lo = mid + 1, right = mid;
else hi = mid - 1;
}
if (left > right) *mn = *mx = -1;
else {
*mn = A[left];
*mx = A[right];
}
if (subtask_num == 1) call_count++;
else if (subtask_num == 2) call_count += right - left + 2;
}
#endif
int n;
const int MAX = 111111;
ll a[MAX];
ll solve1()
{
int l = 0, r = n - 1;
ll L = 0, R = 1e18;
while (l <= r)
{
MinMax(L, R, &a[l], &a[r]);
L = a[l++] + 1;
R = a[r--] - 1;
}
ll ans = -linf;
F0R(i, n - 1)
{
ans = max(ans, a[i + 1] - a[i]);
}
return ans;
}
pll b[MAX];
ll solve()
{
ll L = 0, R = 1e18;
MinMax(L, R, &a[0], &a[n - 1]);
L = a[0], R = a[n - 1];
ll d = (R - L) / (n - 1);
F0R(i, n - 2)
{
MinMax(L, min(R, L + d) - 1, &b[i].f, &b[i].s);
L += d;
}
MinMax(L, R - 1, &b[n - 2].f, &b[n - 2].s);
ll last = -linf, ans = -linf;
F0R(i, n - 1)
{
if (b[i].f == -1)
{
// do nothing
}
else if (b[i].f == b[i].s)
{
if (last != -linf)ans = max(ans, b[i].f - last);
last = b[i].s;
}
else
{
if (last != -linf)ans = max(ans, b[i].f - last);
last = b[i].s;
}
}
ans = max(ans, R - last);
return ans;
}
long long findGap(int subtask, int N)
{
n = N;
if (subtask == 1)
{
return solve1();
}
else
{
return solve();
}
}
#ifdef arwaeystoamneg
int main()
{
setIO("test1");
cin >> subtask_num >> N;
my_assert(1 <= subtask_num && subtask_num <= 2);
my_assert(2 <= N && N <= 100000);
for (int i = 1; i <= N; i++) cin >> A[i];
for (int i = 1; i < N; i++) my_assert(A[i] < A[i + 1]);
cout << findGap(subtask_num, N) << endl << call_count << endl;
}
#endif
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
200 KB |
Output is correct |
2 |
Correct |
0 ms |
328 KB |
Output is correct |
3 |
Correct |
0 ms |
200 KB |
Output is correct |
4 |
Correct |
0 ms |
200 KB |
Output is correct |
5 |
Correct |
0 ms |
200 KB |
Output is correct |
6 |
Correct |
0 ms |
200 KB |
Output is correct |
7 |
Correct |
0 ms |
328 KB |
Output is correct |
8 |
Correct |
0 ms |
328 KB |
Output is correct |
9 |
Correct |
0 ms |
328 KB |
Output is correct |
10 |
Correct |
0 ms |
200 KB |
Output is correct |
11 |
Correct |
1 ms |
328 KB |
Output is correct |
12 |
Correct |
1 ms |
328 KB |
Output is correct |
13 |
Correct |
1 ms |
328 KB |
Output is correct |
14 |
Correct |
1 ms |
328 KB |
Output is correct |
15 |
Correct |
1 ms |
328 KB |
Output is correct |
16 |
Correct |
10 ms |
664 KB |
Output is correct |
17 |
Correct |
11 ms |
676 KB |
Output is correct |
18 |
Correct |
11 ms |
712 KB |
Output is correct |
19 |
Correct |
11 ms |
700 KB |
Output is correct |
20 |
Correct |
9 ms |
712 KB |
Output is correct |
21 |
Correct |
52 ms |
1792 KB |
Output is correct |
22 |
Correct |
46 ms |
1856 KB |
Output is correct |
23 |
Correct |
46 ms |
1768 KB |
Output is correct |
24 |
Correct |
44 ms |
1812 KB |
Output is correct |
25 |
Correct |
38 ms |
1824 KB |
Output is correct |
26 |
Correct |
44 ms |
1820 KB |
Output is correct |
27 |
Correct |
49 ms |
1948 KB |
Output is correct |
28 |
Correct |
43 ms |
1864 KB |
Output is correct |
29 |
Correct |
43 ms |
1804 KB |
Output is correct |
30 |
Correct |
35 ms |
1892 KB |
Output is correct |
31 |
Correct |
0 ms |
328 KB |
Output is correct |
32 |
Correct |
1 ms |
328 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
200 KB |
Output is correct |
2 |
Correct |
0 ms |
328 KB |
Output is correct |
3 |
Correct |
0 ms |
200 KB |
Output is correct |
4 |
Correct |
0 ms |
328 KB |
Output is correct |
5 |
Correct |
0 ms |
328 KB |
Output is correct |
6 |
Correct |
1 ms |
328 KB |
Output is correct |
7 |
Correct |
0 ms |
200 KB |
Output is correct |
8 |
Correct |
1 ms |
328 KB |
Output is correct |
9 |
Correct |
0 ms |
328 KB |
Output is correct |
10 |
Correct |
0 ms |
328 KB |
Output is correct |
11 |
Correct |
1 ms |
328 KB |
Output is correct |
12 |
Correct |
1 ms |
328 KB |
Output is correct |
13 |
Correct |
1 ms |
328 KB |
Output is correct |
14 |
Correct |
2 ms |
328 KB |
Output is correct |
15 |
Correct |
1 ms |
328 KB |
Output is correct |
16 |
Correct |
15 ms |
840 KB |
Output is correct |
17 |
Correct |
14 ms |
912 KB |
Output is correct |
18 |
Correct |
16 ms |
840 KB |
Output is correct |
19 |
Correct |
15 ms |
844 KB |
Output is correct |
20 |
Correct |
8 ms |
840 KB |
Output is correct |
21 |
Correct |
61 ms |
2584 KB |
Output is correct |
22 |
Correct |
60 ms |
2652 KB |
Output is correct |
23 |
Correct |
60 ms |
2624 KB |
Output is correct |
24 |
Correct |
61 ms |
2608 KB |
Output is correct |
25 |
Correct |
55 ms |
2584 KB |
Output is correct |
26 |
Correct |
68 ms |
2596 KB |
Output is correct |
27 |
Correct |
66 ms |
2624 KB |
Output is correct |
28 |
Correct |
76 ms |
2584 KB |
Output is correct |
29 |
Correct |
62 ms |
2624 KB |
Output is correct |
30 |
Correct |
35 ms |
2580 KB |
Output is correct |
31 |
Correct |
0 ms |
200 KB |
Output is correct |
32 |
Correct |
0 ms |
200 KB |
Output is correct |