#include "gap.h"
#include <bits/stdc++.h>
#define pb push_back
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(), (v).end()
using namespace std;
typedef long long lld;
lld findGap(int T, int N)
{
if (T == 1){
lld p = 0, q = (lld)1e18 + 1;
vector <lld> arr;
for (;;){
lld mn, mx;
MinMax(p+1, q-1, &mn, &mx);
arr.pb(mn); arr.pb(mx);
if (mn == mx || sz(arr) == N) break;
p = mn, q = mx;
}
sort(all(arr));
lld ans = 0;
for (int i=1;i<sz(arr);i++)
ans = max(ans, arr[i]-arr[i-1]);
return ans;
}else{
lld mn, mx;
MinMax(1, 1e18, &mn, &mx);
if (N == 2) return mx-mn;
lld size = mx-mn-1;
lld s = mn+1, last = mn, ans = 0;
for (int i=0;i<N-1;i++){
lld e = s + size / (N-1) - 1;
if (i < size % (N-1)) e++;
MinMax(s, e, &mn, &mx);
if (mn != -1){
ans = max(ans, mn - last);
last = mx;
}
s = e+1;
}
return max(ans, s - last);
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
248 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 |
2 ms |
328 KB |
Output is correct |
12 |
Correct |
2 ms |
328 KB |
Output is correct |
13 |
Correct |
1 ms |
324 KB |
Output is correct |
14 |
Correct |
2 ms |
328 KB |
Output is correct |
15 |
Correct |
1 ms |
328 KB |
Output is correct |
16 |
Correct |
15 ms |
840 KB |
Output is correct |
17 |
Correct |
12 ms |
804 KB |
Output is correct |
18 |
Correct |
12 ms |
840 KB |
Output is correct |
19 |
Correct |
15 ms |
832 KB |
Output is correct |
20 |
Correct |
12 ms |
840 KB |
Output is correct |
21 |
Correct |
48 ms |
2252 KB |
Output is correct |
22 |
Correct |
47 ms |
2196 KB |
Output is correct |
23 |
Correct |
49 ms |
2232 KB |
Output is correct |
24 |
Correct |
49 ms |
2232 KB |
Output is correct |
25 |
Correct |
45 ms |
2208 KB |
Output is correct |
26 |
Correct |
55 ms |
2188 KB |
Output is correct |
27 |
Correct |
56 ms |
2172 KB |
Output is correct |
28 |
Correct |
47 ms |
2236 KB |
Output is correct |
29 |
Correct |
51 ms |
2208 KB |
Output is correct |
30 |
Correct |
40 ms |
2216 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 |
200 KB |
Output is correct |
12 |
Correct |
1 ms |
328 KB |
Output is correct |
13 |
Correct |
1 ms |
200 KB |
Output is correct |
14 |
Correct |
2 ms |
328 KB |
Output is correct |
15 |
Correct |
1 ms |
328 KB |
Output is correct |
16 |
Correct |
16 ms |
456 KB |
Output is correct |
17 |
Correct |
15 ms |
620 KB |
Output is correct |
18 |
Correct |
14 ms |
504 KB |
Output is correct |
19 |
Correct |
14 ms |
456 KB |
Output is correct |
20 |
Correct |
8 ms |
456 KB |
Output is correct |
21 |
Correct |
64 ms |
1068 KB |
Output is correct |
22 |
Correct |
58 ms |
1056 KB |
Output is correct |
23 |
Correct |
59 ms |
996 KB |
Output is correct |
24 |
Correct |
57 ms |
1076 KB |
Output is correct |
25 |
Correct |
59 ms |
1076 KB |
Output is correct |
26 |
Correct |
57 ms |
960 KB |
Output is correct |
27 |
Correct |
64 ms |
1072 KB |
Output is correct |
28 |
Correct |
58 ms |
1016 KB |
Output is correct |
29 |
Correct |
61 ms |
1040 KB |
Output is correct |
30 |
Correct |
34 ms |
1056 KB |
Output is correct |
31 |
Correct |
1 ms |
200 KB |
Output is correct |
32 |
Correct |
1 ms |
200 KB |
Output is correct |