#include <bits/stdc++.h>
#include "gap.h"
using namespace std;
typedef long long ll;
long long findGap(int t, int n)
{
ll lo = 0, hi = (ll)1e18;
if (t == 1) {
ll le = 0, ri = n-1, x, y;
vector<ll> a(n);
while (le <= ri) {
MinMax(lo,hi,&x,&y);
if (x == -1) break;
a[le] = x;
a[ri] = y;
lo = x+1;
hi = y-1;
le++;
ri--;
}
ll ans = 0;
for (int q = 1; q < n; q++) {
ans = max(ans, a[q]-a[q-1]);
}
return ans;
} else {
ll x,y;
MinMax(lo,hi,&x,&y);
if (n == 2) return y-x;
ll piece = (y-x-1)/(n-1);
ll add = y-x-1-(n-1)*piece;
vector<pair<ll,ll>> inter;
ll last = x;
for (int q = 0; q < n-1; q++) {
inter.emplace_back(last+1,last+1+piece);
if (add > 0) inter.back().second++;
last = inter.back().second;
}
ll a,b;
vector<pair<ll,ll>> res;
for (int q = 0; q < n-1; q++) {
MinMax(inter[q].first,inter[q].second,&a,&b);
res.emplace_back(a,b);
}
ll ans = 0;
last = x;
for (int q = 0; q < n-1; q++) {
if (res[q].first == -1) continue;
ans = max(ans, res[q].first-last);
ans = max(ans, res[q].second-res[q].first);
last = res[q].second;
}
ans = max(ans, y-last);
return ans;
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
372 KB |
Output is correct |
3 |
Correct |
2 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
2 ms |
364 KB |
Output is correct |
12 |
Correct |
2 ms |
364 KB |
Output is correct |
13 |
Correct |
2 ms |
364 KB |
Output is correct |
14 |
Correct |
2 ms |
372 KB |
Output is correct |
15 |
Correct |
2 ms |
504 KB |
Output is correct |
16 |
Correct |
12 ms |
748 KB |
Output is correct |
17 |
Correct |
11 ms |
748 KB |
Output is correct |
18 |
Correct |
12 ms |
748 KB |
Output is correct |
19 |
Correct |
11 ms |
748 KB |
Output is correct |
20 |
Correct |
9 ms |
748 KB |
Output is correct |
21 |
Correct |
44 ms |
1900 KB |
Output is correct |
22 |
Correct |
45 ms |
1912 KB |
Output is correct |
23 |
Correct |
44 ms |
1900 KB |
Output is correct |
24 |
Correct |
48 ms |
1996 KB |
Output is correct |
25 |
Correct |
39 ms |
1900 KB |
Output is correct |
26 |
Correct |
44 ms |
1900 KB |
Output is correct |
27 |
Correct |
43 ms |
1900 KB |
Output is correct |
28 |
Correct |
48 ms |
1900 KB |
Output is correct |
29 |
Correct |
46 ms |
2028 KB |
Output is correct |
30 |
Correct |
37 ms |
1900 KB |
Output is correct |
31 |
Correct |
1 ms |
364 KB |
Output is correct |
32 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
2 ms |
492 KB |
Output is correct |
12 |
Correct |
2 ms |
492 KB |
Output is correct |
13 |
Correct |
2 ms |
492 KB |
Output is correct |
14 |
Correct |
3 ms |
492 KB |
Output is correct |
15 |
Correct |
2 ms |
492 KB |
Output is correct |
16 |
Correct |
16 ms |
1744 KB |
Output is correct |
17 |
Correct |
17 ms |
1636 KB |
Output is correct |
18 |
Correct |
18 ms |
1636 KB |
Output is correct |
19 |
Correct |
15 ms |
1636 KB |
Output is correct |
20 |
Correct |
10 ms |
1636 KB |
Output is correct |
21 |
Correct |
67 ms |
5852 KB |
Output is correct |
22 |
Correct |
64 ms |
5724 KB |
Output is correct |
23 |
Correct |
64 ms |
5724 KB |
Output is correct |
24 |
Correct |
69 ms |
5864 KB |
Output is correct |
25 |
Correct |
65 ms |
5724 KB |
Output is correct |
26 |
Correct |
71 ms |
5724 KB |
Output is correct |
27 |
Correct |
64 ms |
5852 KB |
Output is correct |
28 |
Correct |
64 ms |
5724 KB |
Output is correct |
29 |
Correct |
65 ms |
5724 KB |
Output is correct |
30 |
Correct |
40 ms |
5852 KB |
Output is correct |
31 |
Correct |
2 ms |
364 KB |
Output is correct |
32 |
Correct |
1 ms |
364 KB |
Output is correct |