#include <bits/stdc++.h>
#include "gap.h"
using namespace std;
const long long INF = 1e18;
long long solve1(int N) {
long long a[N+1];
int l = 1, r = N;
long long lef = 0, rit = INF;
while(l<=r) {
MinMax(lef, rit, &lef, &rit);
if(l==r) {
a[l] = lef;
break;
} else {
a[l] = lef, a[r] = rit;
++lef, --rit;
++l, --r;
}
}
long long best = 0;
for(int i=2; i<=N; ++i) {
best = max(best, a[i] - a[i-1]);
}
return best;
}
long long solve2(int N) {
long long lef = 0;
long long absmn, absmx = INF;
MinMax(0, INF, &absmn, &absmx);
lef = absmn + 1;
long long already = (absmx-absmn+N)/N;
while(lef+already+1<=absmx) {
long long pw = already;
while(1) {
long long rit = min(INF, pw+lef-1);
long long var1, var2;
MinMax(lef, rit, &var1, &var2);
if(var1==-1) {
pw *= 2;
} else {
already = max(already, var1 - lef + 1);
lef = var2 + 1;
break;
}
}
}
return already;
}
long long findGap(int T, int N) {
if(T==1) return solve1(N);
else return solve2(N);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
0 ms |
208 KB |
Output is correct |
3 |
Correct |
1 ms |
208 KB |
Output is correct |
4 |
Correct |
0 ms |
296 KB |
Output is correct |
5 |
Correct |
0 ms |
208 KB |
Output is correct |
6 |
Correct |
0 ms |
208 KB |
Output is correct |
7 |
Correct |
0 ms |
208 KB |
Output is correct |
8 |
Correct |
0 ms |
208 KB |
Output is correct |
9 |
Correct |
0 ms |
208 KB |
Output is correct |
10 |
Correct |
0 ms |
208 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
1 ms |
336 KB |
Output is correct |
16 |
Correct |
10 ms |
596 KB |
Output is correct |
17 |
Correct |
11 ms |
592 KB |
Output is correct |
18 |
Correct |
10 ms |
608 KB |
Output is correct |
19 |
Correct |
10 ms |
708 KB |
Output is correct |
20 |
Correct |
9 ms |
680 KB |
Output is correct |
21 |
Correct |
36 ms |
1824 KB |
Output is correct |
22 |
Correct |
40 ms |
1828 KB |
Output is correct |
23 |
Correct |
47 ms |
1864 KB |
Output is correct |
24 |
Correct |
45 ms |
1772 KB |
Output is correct |
25 |
Correct |
38 ms |
1784 KB |
Output is correct |
26 |
Correct |
45 ms |
1852 KB |
Output is correct |
27 |
Correct |
42 ms |
1808 KB |
Output is correct |
28 |
Correct |
46 ms |
1792 KB |
Output is correct |
29 |
Correct |
38 ms |
1768 KB |
Output is correct |
30 |
Correct |
32 ms |
1872 KB |
Output is correct |
31 |
Correct |
1 ms |
208 KB |
Output is correct |
32 |
Correct |
0 ms |
208 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
0 ms |
208 KB |
Output is correct |
3 |
Correct |
0 ms |
208 KB |
Output is correct |
4 |
Correct |
0 ms |
208 KB |
Output is correct |
5 |
Correct |
0 ms |
208 KB |
Output is correct |
6 |
Correct |
0 ms |
208 KB |
Output is correct |
7 |
Correct |
0 ms |
208 KB |
Output is correct |
8 |
Correct |
1 ms |
208 KB |
Output is correct |
9 |
Correct |
0 ms |
208 KB |
Output is correct |
10 |
Correct |
0 ms |
208 KB |
Output is correct |
11 |
Correct |
1 ms |
208 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
13 |
Correct |
1 ms |
336 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
1 ms |
244 KB |
Output is correct |
16 |
Correct |
7 ms |
464 KB |
Output is correct |
17 |
Correct |
8 ms |
500 KB |
Output is correct |
18 |
Correct |
7 ms |
464 KB |
Output is correct |
19 |
Correct |
8 ms |
464 KB |
Output is correct |
20 |
Correct |
5 ms |
464 KB |
Output is correct |
21 |
Correct |
25 ms |
1064 KB |
Output is correct |
22 |
Correct |
26 ms |
1056 KB |
Output is correct |
23 |
Correct |
25 ms |
1096 KB |
Output is correct |
24 |
Correct |
27 ms |
988 KB |
Output is correct |
25 |
Correct |
52 ms |
968 KB |
Output is correct |
26 |
Correct |
26 ms |
1020 KB |
Output is correct |
27 |
Correct |
32 ms |
988 KB |
Output is correct |
28 |
Correct |
25 ms |
964 KB |
Output is correct |
29 |
Correct |
31 ms |
992 KB |
Output is correct |
30 |
Correct |
14 ms |
984 KB |
Output is correct |
31 |
Correct |
0 ms |
208 KB |
Output is correct |
32 |
Correct |
0 ms |
208 KB |
Output is correct |