#include "gap.h"
#include <bits/stdc++.h>
using namespace std;
const long long inff = 1e18;
long long findGap(int t, int n) {
if (t == 1) {
long long l = 0, r = inff;
vector<long long> a(n);
for (int i = 0; i < (n + 1) / 2; i++) {
long long mn, mx;
MinMax(l, r, &mn, &mx);
a[i] = mn;
a[n - 1 - i] = mx;
l = mn + 1;
r = mx - 1;
}
long long ans = 0;
for (int i = 0; i < n - 1; i++) ans = max(ans, a[i + 1] - a[i]);
return ans;
} else if (t == 2) {
long long l = 0, r = inff, mn, mx;
MinMax(l, r, &mn, &mx);
long long ans = (mx - mn) / (n - 1), lst = mn;
l = mn + 1;
r = mx;
while (l < r) {
MinMax(l, l + ans - 1, &mn, &mx);
l += ans;
ans = max(ans, mn - lst);
if (mx != -1) lst = mx;
}
ans = max(ans, r - lst);
return ans;
}
}
Compilation message
gap.cpp: In function 'long long int findGap(int, int)':
gap.cpp:42:1: warning: control reaches end of non-void function [-Wreturn-type]
42 | }
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
1 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
344 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
0 ms |
344 KB |
Output is correct |
13 |
Correct |
1 ms |
344 KB |
Output is correct |
14 |
Correct |
1 ms |
344 KB |
Output is correct |
15 |
Correct |
0 ms |
344 KB |
Output is correct |
16 |
Correct |
6 ms |
856 KB |
Output is correct |
17 |
Correct |
10 ms |
660 KB |
Output is correct |
18 |
Correct |
6 ms |
856 KB |
Output is correct |
19 |
Correct |
9 ms |
660 KB |
Output is correct |
20 |
Correct |
5 ms |
856 KB |
Output is correct |
21 |
Correct |
30 ms |
2012 KB |
Output is correct |
22 |
Correct |
31 ms |
1912 KB |
Output is correct |
23 |
Correct |
25 ms |
1880 KB |
Output is correct |
24 |
Correct |
25 ms |
1880 KB |
Output is correct |
25 |
Correct |
23 ms |
1880 KB |
Output is correct |
26 |
Correct |
25 ms |
1880 KB |
Output is correct |
27 |
Correct |
27 ms |
1880 KB |
Output is correct |
28 |
Correct |
34 ms |
1800 KB |
Output is correct |
29 |
Correct |
25 ms |
1816 KB |
Output is correct |
30 |
Correct |
20 ms |
1880 KB |
Output is correct |
31 |
Correct |
0 ms |
344 KB |
Output is correct |
32 |
Correct |
0 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
344 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
0 ms |
344 KB |
Output is correct |
13 |
Correct |
0 ms |
344 KB |
Output is correct |
14 |
Correct |
0 ms |
344 KB |
Output is correct |
15 |
Correct |
1 ms |
344 KB |
Output is correct |
16 |
Correct |
4 ms |
600 KB |
Output is correct |
17 |
Correct |
5 ms |
432 KB |
Output is correct |
18 |
Correct |
4 ms |
600 KB |
Output is correct |
19 |
Correct |
5 ms |
588 KB |
Output is correct |
20 |
Correct |
3 ms |
600 KB |
Output is correct |
21 |
Correct |
17 ms |
1216 KB |
Output is correct |
22 |
Correct |
17 ms |
1112 KB |
Output is correct |
23 |
Correct |
17 ms |
1112 KB |
Output is correct |
24 |
Correct |
23 ms |
1112 KB |
Output is correct |
25 |
Correct |
32 ms |
1112 KB |
Output is correct |
26 |
Correct |
17 ms |
1112 KB |
Output is correct |
27 |
Correct |
17 ms |
1112 KB |
Output is correct |
28 |
Correct |
17 ms |
1112 KB |
Output is correct |
29 |
Correct |
18 ms |
1112 KB |
Output is correct |
30 |
Correct |
15 ms |
1112 KB |
Output is correct |
31 |
Correct |
0 ms |
344 KB |
Output is correct |
32 |
Correct |
0 ms |
344 KB |
Output is correct |