#include <gap.h>
#include <bits/stdc++.h>
// #include "grader.cpp"
#define ll long long
#define ok puts("ok");
const int inf = (int)1e9 + 7;
using namespace std;
ll solve1(int n) {
long long left;
long long right;
left = 0;
right = 1e18;
long long mn = 0, mx = 1e18;
long long vec[n];
int cnt = 0;
int cn = n - 1;
while (cnt <= cn) {
MinMax(left, right, &mn, &mx);
vec[cnt++] = mn;
if (mn != mx)
vec[cn--] = mx;
left = mn + 1;
right = mx - 1;
}
long long ans = 0;
for (int i = 1; i < n; i++) {
if (vec[i] - vec[i - 1] > ans) {
ans = vec[i] - vec[i - 1];
}
}
return ans;
}
ll findGap(int t, int n) {
if (t == 1) {
return solve1(n);
}
ll l, r;
MinMax(0, 1e18, &l, &r);
if (n == 2) {
return r - l;
} else if (r - l + 1 == n) {
return 1;
}
if(r - l + 1 == n + 1) {
return 2;
}
ll dif = (r - l + 1) / (n + 1);
ll x = (r - l + 1) % (n + 1);
if (x) dif++;
else x = inf;
ll start = l;
ll fin = start + dif - 1;
ll fre = 0;
ll mx = 0;
ll ans = 0;
ll blockes = 0;
ll l1, r1;
while (1) {
blockes++;
if (blockes == 1) {
if (dif == 1) {
l1 = r1 = l;
} else {
MinMax(start + 1, fin, &l1, &r1);
l1 = l;
if (r1 == -1) r1 = l;
}
} else if (blockes == n + 1) {
if (dif == 1) {
l1 = r1 = r;
} else {
MinMax(start, fin - 1, &l1, &r1);
r1 = r;
if (l1 == -1) l1 = r;
}
} else {
MinMax(start, fin, &l1, &r1);
}
x--;
// printf("#blocks %lld\n", blockes);
// cout << blockes << ' ' << dif << endl;
// cout << start << ' ' << fin << endl;
// cout << l1 << ' ' << r1 << endl;
if (l1 == -1) {
fre += dif;
} else {
if (fre != 0) {
ans = max(ans, fre + mx + (l1 - start + 1));
}
fre = 0;
mx = fin - r1;
}
if (fin == r) break;
if (x <= 0) {
dif--;
x = inf;
}
start = fin + 1;
fin = min(start + dif - 1, r);
}
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
1 ms |
376 KB |
Output is correct |
3 |
Correct |
1 ms |
424 KB |
Output is correct |
4 |
Correct |
1 ms |
424 KB |
Output is correct |
5 |
Correct |
2 ms |
424 KB |
Output is correct |
6 |
Correct |
1 ms |
464 KB |
Output is correct |
7 |
Correct |
2 ms |
532 KB |
Output is correct |
8 |
Correct |
2 ms |
532 KB |
Output is correct |
9 |
Correct |
1 ms |
548 KB |
Output is correct |
10 |
Correct |
2 ms |
548 KB |
Output is correct |
11 |
Correct |
2 ms |
600 KB |
Output is correct |
12 |
Correct |
2 ms |
696 KB |
Output is correct |
13 |
Correct |
2 ms |
696 KB |
Output is correct |
14 |
Correct |
3 ms |
696 KB |
Output is correct |
15 |
Correct |
2 ms |
728 KB |
Output is correct |
16 |
Correct |
16 ms |
1004 KB |
Output is correct |
17 |
Correct |
17 ms |
1004 KB |
Output is correct |
18 |
Correct |
15 ms |
1004 KB |
Output is correct |
19 |
Correct |
14 ms |
1004 KB |
Output is correct |
20 |
Correct |
12 ms |
1004 KB |
Output is correct |
21 |
Correct |
52 ms |
2156 KB |
Output is correct |
22 |
Correct |
54 ms |
2156 KB |
Output is correct |
23 |
Correct |
62 ms |
2156 KB |
Output is correct |
24 |
Correct |
54 ms |
2156 KB |
Output is correct |
25 |
Correct |
46 ms |
2160 KB |
Output is correct |
26 |
Correct |
53 ms |
2160 KB |
Output is correct |
27 |
Correct |
54 ms |
2160 KB |
Output is correct |
28 |
Correct |
52 ms |
2160 KB |
Output is correct |
29 |
Correct |
53 ms |
2252 KB |
Output is correct |
30 |
Correct |
39 ms |
2252 KB |
Output is correct |
31 |
Correct |
2 ms |
2252 KB |
Output is correct |
32 |
Correct |
1 ms |
2252 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2252 KB |
Output is correct |
2 |
Correct |
1 ms |
2252 KB |
Output is correct |
3 |
Correct |
2 ms |
2252 KB |
Output is correct |
4 |
Correct |
2 ms |
2252 KB |
Output is correct |
5 |
Correct |
1 ms |
2252 KB |
Output is correct |
6 |
Correct |
1 ms |
2252 KB |
Output is correct |
7 |
Correct |
1 ms |
2252 KB |
Output is correct |
8 |
Correct |
2 ms |
2252 KB |
Output is correct |
9 |
Correct |
2 ms |
2252 KB |
Output is correct |
10 |
Correct |
1 ms |
2252 KB |
Output is correct |
11 |
Correct |
2 ms |
2252 KB |
Output is correct |
12 |
Correct |
3 ms |
2252 KB |
Output is correct |
13 |
Correct |
3 ms |
2252 KB |
Output is correct |
14 |
Correct |
3 ms |
2252 KB |
Output is correct |
15 |
Correct |
2 ms |
2252 KB |
Output is correct |
16 |
Correct |
19 ms |
2252 KB |
Output is correct |
17 |
Correct |
19 ms |
2252 KB |
Output is correct |
18 |
Correct |
21 ms |
2252 KB |
Output is correct |
19 |
Correct |
19 ms |
2252 KB |
Output is correct |
20 |
Correct |
9 ms |
2252 KB |
Output is correct |
21 |
Correct |
70 ms |
2252 KB |
Output is correct |
22 |
Correct |
73 ms |
2252 KB |
Output is correct |
23 |
Correct |
71 ms |
2252 KB |
Output is correct |
24 |
Correct |
72 ms |
2252 KB |
Output is correct |
25 |
Correct |
67 ms |
2252 KB |
Output is correct |
26 |
Correct |
74 ms |
2252 KB |
Output is correct |
27 |
Correct |
71 ms |
2252 KB |
Output is correct |
28 |
Correct |
71 ms |
2252 KB |
Output is correct |
29 |
Correct |
71 ms |
2252 KB |
Output is correct |
30 |
Correct |
39 ms |
2252 KB |
Output is correct |
31 |
Correct |
1 ms |
2252 KB |
Output is correct |
32 |
Correct |
1 ms |
2252 KB |
Output is correct |