# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
946609 |
2024-03-14T19:43:03 Z |
n3rm1n |
Gap (APIO16_gap) |
C++17 |
|
37 ms |
3604 KB |
#include<bits/stdc++.h>
#include "gap.h"
using namespace std;
const long long MAXN = 2e5 + 10;
long long a[MAXN];
long long findGap(int T, int N)
{
if(T == 1)
{
long long s = 0, t = (long long)(1e18);
long long mn, mx;
long long n = N;
long long filled0 = 0, filled1 = n+1;
while(filled0 + 1 <= filled1 - 1)
{
MinMax(s, t, &mn, &mx);
if(mn == mx)
{
filled0 ++;
a[filled0] = mn;
n --;
break;
}
filled0 ++;
filled1 --;
n-= 2;
a[filled0] = mn;
a[filled1] = mx;
s = mn + 1;
t = mx - 1;
}
long long ans = -1;
//cout << "n is " << n << endl;
//cout << a[1] << " ";
for (long long i = 2; i <= N; ++ i)
{
//cout << a[i] << " ";
ans = max(ans, (long long) (a[i] - a[i-1]));
}
//cout << endl;
//cout << ans << endl;
return ans;
}
long long s = 0, t = (long long)(1e18), mn, mx;
MinMax(s, t, &mn, &mx);
long long curr = mn, last = mx;
long long ans = 1;
priority_queue < long long > q;
while(curr < last)
{
// cout << curr << endl;
// cout << "* " << ans << endl;
s = curr + 1;
t = curr + ans;
if(s <= t)
{
MinMax(s, t, &mn, &mx);
if(mn != -1 && mx != -1)
{
curr = mx;
//cout << "move to " << curr << endl;
continue;
}
}
while(!q.empty() && -q.top() <= -curr)
{
q.pop();
}
long long limit = last;
if(!q.empty())limit = -q.top();
long long lf = ans, rth = min(limit - curr, last - curr), mid, newans = -1;
//q.clear();
long long found = 0;
while(lf <= rth)
{
mid = (rth - lf)/2 + lf;
s = curr + 1;
t = curr + mid + 1;
MinMax(s, t, &mn, &mx);
if(mn == -1 && mx == -1)
{
lf = mid + 1;
}
else
{
rth = mid - 1;
q.push(-mx);
found = mx;
newans = mid;
}
}
// cout << "found is " << found << endl;
if(newans != -1)ans = found - curr;
else break;
curr = found;
}
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
2392 KB |
Output is correct |
3 |
Correct |
1 ms |
2392 KB |
Output is correct |
4 |
Correct |
0 ms |
2392 KB |
Output is correct |
5 |
Correct |
0 ms |
2392 KB |
Output is correct |
6 |
Correct |
1 ms |
2392 KB |
Output is correct |
7 |
Correct |
1 ms |
2392 KB |
Output is correct |
8 |
Correct |
1 ms |
2392 KB |
Output is correct |
9 |
Correct |
1 ms |
2392 KB |
Output is correct |
10 |
Correct |
1 ms |
2392 KB |
Output is correct |
11 |
Correct |
1 ms |
2392 KB |
Output is correct |
12 |
Correct |
1 ms |
2392 KB |
Output is correct |
13 |
Correct |
1 ms |
2392 KB |
Output is correct |
14 |
Correct |
1 ms |
2392 KB |
Output is correct |
15 |
Correct |
1 ms |
2392 KB |
Output is correct |
16 |
Correct |
7 ms |
2680 KB |
Output is correct |
17 |
Correct |
7 ms |
2536 KB |
Output is correct |
18 |
Correct |
7 ms |
2704 KB |
Output is correct |
19 |
Correct |
7 ms |
2792 KB |
Output is correct |
20 |
Correct |
6 ms |
2536 KB |
Output is correct |
21 |
Correct |
28 ms |
3448 KB |
Output is correct |
22 |
Correct |
27 ms |
3232 KB |
Output is correct |
23 |
Correct |
28 ms |
3452 KB |
Output is correct |
24 |
Correct |
29 ms |
3452 KB |
Output is correct |
25 |
Correct |
25 ms |
3440 KB |
Output is correct |
26 |
Correct |
28 ms |
3452 KB |
Output is correct |
27 |
Correct |
31 ms |
3604 KB |
Output is correct |
28 |
Correct |
28 ms |
3448 KB |
Output is correct |
29 |
Correct |
28 ms |
3452 KB |
Output is correct |
30 |
Correct |
23 ms |
3400 KB |
Output is correct |
31 |
Correct |
0 ms |
2392 KB |
Output is correct |
32 |
Correct |
0 ms |
2392 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Partially correct |
1 ms |
2392 KB |
Partially correct |
2 |
Incorrect |
1 ms |
2392 KB |
Output isn't correct |
3 |
Incorrect |
0 ms |
2392 KB |
Output isn't correct |
4 |
Incorrect |
1 ms |
2392 KB |
Output isn't correct |
5 |
Partially correct |
1 ms |
2392 KB |
Partially correct |
6 |
Incorrect |
1 ms |
2644 KB |
Output isn't correct |
7 |
Incorrect |
1 ms |
2392 KB |
Output isn't correct |
8 |
Incorrect |
1 ms |
2392 KB |
Output isn't correct |
9 |
Incorrect |
1 ms |
2392 KB |
Output isn't correct |
10 |
Incorrect |
1 ms |
2392 KB |
Output isn't correct |
11 |
Incorrect |
1 ms |
2392 KB |
Output isn't correct |
12 |
Incorrect |
1 ms |
2392 KB |
Output isn't correct |
13 |
Incorrect |
1 ms |
2392 KB |
Output isn't correct |
14 |
Incorrect |
1 ms |
2392 KB |
Output isn't correct |
15 |
Partially correct |
1 ms |
2392 KB |
Partially correct |
16 |
Incorrect |
3 ms |
2536 KB |
Output isn't correct |
17 |
Incorrect |
4 ms |
2708 KB |
Output isn't correct |
18 |
Incorrect |
5 ms |
2696 KB |
Output isn't correct |
19 |
Incorrect |
6 ms |
2532 KB |
Output isn't correct |
20 |
Incorrect |
5 ms |
2536 KB |
Output isn't correct |
21 |
Incorrect |
12 ms |
2684 KB |
Output isn't correct |
22 |
Incorrect |
12 ms |
2684 KB |
Output isn't correct |
23 |
Incorrect |
12 ms |
2684 KB |
Output isn't correct |
24 |
Incorrect |
12 ms |
2680 KB |
Output isn't correct |
25 |
Partially correct |
37 ms |
2676 KB |
Partially correct |
26 |
Incorrect |
13 ms |
2928 KB |
Output isn't correct |
27 |
Incorrect |
12 ms |
2684 KB |
Output isn't correct |
28 |
Incorrect |
12 ms |
2680 KB |
Output isn't correct |
29 |
Incorrect |
12 ms |
2684 KB |
Output isn't correct |
30 |
Incorrect |
16 ms |
2780 KB |
Output isn't correct |
31 |
Incorrect |
1 ms |
2392 KB |
Output isn't correct |
32 |
Correct |
0 ms |
2392 KB |
Output is correct |