#include "gap.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll findGap(int T, int N) {
const ll inf = 1'000'000'000'000'000'000LL;
ll mn = -1, mx = inf + 1;
if (T == 1) {
vector<ll> a(N);
ll ans = -inf;
for (int l = 0, r = N - 1; l <= r; ++l, --r) {
MinMax(mn + 1, mx - 1, &mn, &mx);
assert(mn != -1);
a[l] = mn, a[r] = mx;
}
for (int i = 0; i < N - 1; ++i) {
ans = max(ans, a[i + 1] - a[i]);
}
return ans;
} else {
MinMax(0, inf, &mn, &mx);
ll sum = mx - mn;
ll ans = -inf;
ll len = (sum + (N - 1) - 1) / (N - 1);
ll R = mx;
for (int i = N - 1; i > 0; --i) {
ll nw = mx;
MinMax(mx - len, mx - 1, &mn, &mx);
if (mx != -1) {
ans = max(ans, R - mx);
R = mn;
}
mx = nw - len;
}
return ans;
}
}
# |
결과 |
실행 시간 |
메모리 |
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 |
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 |
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 |
592 KB |
Output is correct |
17 |
Correct |
13 ms |
680 KB |
Output is correct |
18 |
Correct |
10 ms |
720 KB |
Output is correct |
19 |
Correct |
9 ms |
720 KB |
Output is correct |
20 |
Correct |
8 ms |
720 KB |
Output is correct |
21 |
Correct |
39 ms |
1864 KB |
Output is correct |
22 |
Correct |
37 ms |
1836 KB |
Output is correct |
23 |
Correct |
36 ms |
1812 KB |
Output is correct |
24 |
Correct |
36 ms |
1864 KB |
Output is correct |
25 |
Correct |
34 ms |
1872 KB |
Output is correct |
26 |
Correct |
42 ms |
1776 KB |
Output is correct |
27 |
Correct |
37 ms |
1836 KB |
Output is correct |
28 |
Correct |
36 ms |
1820 KB |
Output is correct |
29 |
Correct |
35 ms |
1824 KB |
Output is correct |
30 |
Correct |
28 ms |
1872 KB |
Output is correct |
31 |
Correct |
0 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 |
256 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 |
208 KB |
Output is correct |
13 |
Correct |
1 ms |
208 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
1 ms |
336 KB |
Output is correct |
16 |
Correct |
12 ms |
464 KB |
Output is correct |
17 |
Correct |
14 ms |
464 KB |
Output is correct |
18 |
Correct |
13 ms |
492 KB |
Output is correct |
19 |
Correct |
13 ms |
520 KB |
Output is correct |
20 |
Correct |
7 ms |
472 KB |
Output is correct |
21 |
Correct |
53 ms |
1056 KB |
Output is correct |
22 |
Correct |
51 ms |
964 KB |
Output is correct |
23 |
Correct |
51 ms |
976 KB |
Output is correct |
24 |
Correct |
50 ms |
1060 KB |
Output is correct |
25 |
Correct |
47 ms |
968 KB |
Output is correct |
26 |
Correct |
50 ms |
1064 KB |
Output is correct |
27 |
Correct |
62 ms |
1084 KB |
Output is correct |
28 |
Correct |
55 ms |
1076 KB |
Output is correct |
29 |
Correct |
52 ms |
1024 KB |
Output is correct |
30 |
Correct |
28 ms |
976 KB |
Output is correct |
31 |
Correct |
0 ms |
208 KB |
Output is correct |
32 |
Correct |
0 ms |
208 KB |
Output is correct |