#include "gap.h"
#include <bits/stdc++.h>
using namespace std;
long long findGap(int T, int N) {
vector<long long> a;
if (T == 1) {
long long lb = 0, rb = (long long) 1e18L;
a.resize(N);
for (int i = 0; i < (N + 1) / 2; i++) {
MinMax(lb, rb, &a[i], &a[N - 1 - i]);
lb = a[i] + 1;
rb = a[N - 1 - i] - 1;
}
long long ans = 0;
for (int i = 1; i < N; i++) {
ans = max(ans, a[i] - a[i - 1]);
}
return ans;
}
long long mn, mx;
MinMax(0, 1e18L, &mn, &mx);
if (N == 2) {
return mx - mn;
}
if (N == 3) {
long long nn;
MinMax(0, mx - 1, &mn, &nn);
return max(nn - mn, mx - nn);
}
if (mx - mn == N - 1) {
return 1LL;
}
long long len = (mx - mn - 1) / (N - 1);
long long ans = len;
a.push_back(mn);
for (int i = 0; i < N - 1; i++) {
long long m, M;
if (mn + 1 == mx - 1) {
a.push_back(mn + 1);
break;
}
if (mn + 1 > mx - 1) {
break;
}
MinMax(mn + 1, min(mn + 1 + len, mx - 1), &m, &M);
mn = mn + 1 + len;
if (m == -1) {
continue;
}
a.push_back(m);
if (M != m) {
a.push_back(M);
}
}
a.push_back(mx);
for (int i = 1; i < (int) a.size(); i++) {
ans = max(ans, a[i] - a[i - 1]);
}
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
200 KB |
Output is correct |
2 |
Correct |
1 ms |
200 KB |
Output is correct |
3 |
Correct |
1 ms |
200 KB |
Output is correct |
4 |
Correct |
1 ms |
200 KB |
Output is correct |
5 |
Correct |
1 ms |
200 KB |
Output is correct |
6 |
Correct |
1 ms |
200 KB |
Output is correct |
7 |
Correct |
1 ms |
200 KB |
Output is correct |
8 |
Correct |
1 ms |
200 KB |
Output is correct |
9 |
Correct |
1 ms |
200 KB |
Output is correct |
10 |
Correct |
1 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 |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
444 KB |
Output is correct |
15 |
Correct |
1 ms |
328 KB |
Output is correct |
16 |
Correct |
12 ms |
704 KB |
Output is correct |
17 |
Correct |
11 ms |
676 KB |
Output is correct |
18 |
Correct |
12 ms |
676 KB |
Output is correct |
19 |
Correct |
11 ms |
712 KB |
Output is correct |
20 |
Correct |
9 ms |
584 KB |
Output is correct |
21 |
Correct |
43 ms |
1780 KB |
Output is correct |
22 |
Correct |
42 ms |
1812 KB |
Output is correct |
23 |
Correct |
43 ms |
1824 KB |
Output is correct |
24 |
Correct |
44 ms |
1920 KB |
Output is correct |
25 |
Correct |
37 ms |
1844 KB |
Output is correct |
26 |
Correct |
42 ms |
1836 KB |
Output is correct |
27 |
Correct |
44 ms |
1816 KB |
Output is correct |
28 |
Correct |
46 ms |
1876 KB |
Output is correct |
29 |
Correct |
43 ms |
1856 KB |
Output is correct |
30 |
Correct |
34 ms |
1860 KB |
Output is correct |
31 |
Correct |
1 ms |
200 KB |
Output is correct |
32 |
Correct |
1 ms |
200 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
200 KB |
Output is correct |
2 |
Correct |
1 ms |
200 KB |
Output is correct |
3 |
Correct |
1 ms |
200 KB |
Output is correct |
4 |
Correct |
1 ms |
200 KB |
Output is correct |
5 |
Correct |
1 ms |
200 KB |
Output is correct |
6 |
Correct |
1 ms |
200 KB |
Output is correct |
7 |
Correct |
1 ms |
200 KB |
Output is correct |
8 |
Correct |
1 ms |
200 KB |
Output is correct |
9 |
Correct |
1 ms |
200 KB |
Output is correct |
10 |
Correct |
1 ms |
200 KB |
Output is correct |
11 |
Correct |
1 ms |
328 KB |
Output is correct |
12 |
Correct |
2 ms |
328 KB |
Output is correct |
13 |
Correct |
2 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 |
18 ms |
880 KB |
Output is correct |
17 |
Correct |
15 ms |
840 KB |
Output is correct |
18 |
Correct |
16 ms |
888 KB |
Output is correct |
19 |
Correct |
16 ms |
840 KB |
Output is correct |
20 |
Correct |
8 ms |
528 KB |
Output is correct |
21 |
Correct |
64 ms |
2160 KB |
Output is correct |
22 |
Correct |
67 ms |
2172 KB |
Output is correct |
23 |
Correct |
69 ms |
2244 KB |
Output is correct |
24 |
Correct |
63 ms |
2160 KB |
Output is correct |
25 |
Correct |
55 ms |
2192 KB |
Output is correct |
26 |
Correct |
71 ms |
2364 KB |
Output is correct |
27 |
Correct |
65 ms |
2196 KB |
Output is correct |
28 |
Correct |
61 ms |
2196 KB |
Output is correct |
29 |
Correct |
66 ms |
2196 KB |
Output is correct |
30 |
Correct |
37 ms |
1432 KB |
Output is correct |
31 |
Correct |
1 ms |
200 KB |
Output is correct |
32 |
Correct |
1 ms |
200 KB |
Output is correct |