#include "gap.h"
#include <bits/stdc++.h>
using namespace std;
const long long maxa = 1e18;
long long diff, mn, mx, T, N;
long long mntp, mxtp, ans = 0, last;
void solve1() {
MinMax(1, maxa, &mn, &mx);
for(int i = 3; i <= N; i += 2) {
MinMax(mn + 1, mx - 1, &mntp, &mxtp);
ans = max(ans, mntp - mn);
ans = max(ans, mx - mxtp);
mn = mntp, mx = mxtp;
}
ans = max(ans, mx - mn);
}
void solve2() {
MinMax(1, maxa, &mn, &mx);
if(N == 2) {
ans = mx - mn;
return;
}
long long seg = (mx - mn - 1) / (N - 2);
last = mn;
for(long long i = mn + 1; i < mx; i += seg + 1) {
MinMax(i, min(i + seg, mx - 1), &mntp, &mxtp);
if(mntp != -1) {
ans = max(ans, mntp - last);
last = mxtp;
}
}
ans = max(ans, mx - last);
}
long long findGap(int a0, int b1) {
T = a0, N = b1;
if(T == 1) {
solve1();
}else solve2();
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
256 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
4 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
4 ms |
384 KB |
Output is correct |
8 |
Correct |
4 ms |
384 KB |
Output is correct |
9 |
Correct |
4 ms |
384 KB |
Output is correct |
10 |
Correct |
4 ms |
384 KB |
Output is correct |
11 |
Correct |
5 ms |
384 KB |
Output is correct |
12 |
Correct |
5 ms |
384 KB |
Output is correct |
13 |
Correct |
5 ms |
384 KB |
Output is correct |
14 |
Correct |
5 ms |
384 KB |
Output is correct |
15 |
Correct |
5 ms |
384 KB |
Output is correct |
16 |
Correct |
16 ms |
512 KB |
Output is correct |
17 |
Correct |
16 ms |
512 KB |
Output is correct |
18 |
Correct |
16 ms |
512 KB |
Output is correct |
19 |
Correct |
16 ms |
512 KB |
Output is correct |
20 |
Correct |
12 ms |
512 KB |
Output is correct |
21 |
Correct |
53 ms |
1148 KB |
Output is correct |
22 |
Correct |
53 ms |
1144 KB |
Output is correct |
23 |
Correct |
52 ms |
1144 KB |
Output is correct |
24 |
Correct |
64 ms |
1120 KB |
Output is correct |
25 |
Correct |
46 ms |
1144 KB |
Output is correct |
26 |
Correct |
55 ms |
1272 KB |
Output is correct |
27 |
Correct |
55 ms |
1136 KB |
Output is correct |
28 |
Correct |
52 ms |
1052 KB |
Output is correct |
29 |
Correct |
52 ms |
1168 KB |
Output is correct |
30 |
Correct |
39 ms |
1272 KB |
Output is correct |
31 |
Correct |
5 ms |
384 KB |
Output is correct |
32 |
Correct |
4 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
5 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
4 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
5 ms |
384 KB |
Output is correct |
8 |
Correct |
4 ms |
384 KB |
Output is correct |
9 |
Correct |
5 ms |
384 KB |
Output is correct |
10 |
Correct |
5 ms |
384 KB |
Output is correct |
11 |
Correct |
5 ms |
384 KB |
Output is correct |
12 |
Correct |
5 ms |
384 KB |
Output is correct |
13 |
Correct |
5 ms |
384 KB |
Output is correct |
14 |
Correct |
5 ms |
384 KB |
Output is correct |
15 |
Correct |
5 ms |
384 KB |
Output is correct |
16 |
Correct |
20 ms |
512 KB |
Output is correct |
17 |
Correct |
20 ms |
512 KB |
Output is correct |
18 |
Correct |
20 ms |
512 KB |
Output is correct |
19 |
Correct |
20 ms |
512 KB |
Output is correct |
20 |
Correct |
12 ms |
512 KB |
Output is correct |
21 |
Correct |
74 ms |
1108 KB |
Output is correct |
22 |
Correct |
69 ms |
1144 KB |
Output is correct |
23 |
Correct |
71 ms |
1188 KB |
Output is correct |
24 |
Correct |
69 ms |
1144 KB |
Output is correct |
25 |
Correct |
63 ms |
1144 KB |
Output is correct |
26 |
Correct |
70 ms |
1144 KB |
Output is correct |
27 |
Correct |
70 ms |
1072 KB |
Output is correct |
28 |
Correct |
70 ms |
1144 KB |
Output is correct |
29 |
Correct |
70 ms |
1272 KB |
Output is correct |
30 |
Correct |
44 ms |
1144 KB |
Output is correct |
31 |
Correct |
5 ms |
288 KB |
Output is correct |
32 |
Correct |
5 ms |
384 KB |
Output is correct |