//In the name of God
#include <bits/stdc++.h>
using namespace std;
#include "gap.h"
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const ll maxn = 2e5 + 100;
const ll mod = 1e9 + 7;
const ll inf = 1e18 + 1000;
#define fast_io ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define file_io freopen("input.txt", "r+", stdin);freopen("output.txt", "w+", stdout);
#define pb push_back
#define Mp make_pair
#define F first
#define S second
#define Sz(x) ll((x).size())
#define all(x) (x).begin(), (x).end()
ll pw(ll a, ll b){
ll c = 1;
while(b){
if(b & 1) c = c * a % mod;
a = a * a % mod;
b >>= 1;
}
return c;
}
ll mn, mx, L, R, ans;
ll a[maxn];
ll solve(int n){
L = 0;
R = inf;
for(int i = 0; i < (n + 1) / 2; i++){
MinMax(L, R, &mn, &mx);
a[i] = mn;
a[n - i - 1] = mx;
L = mn + 1;
R = mx - 1;
}
for(int i = 1; i < n; i++){
ans = max(ans, a[i] - a[i - 1]);
}
return ans;
}
long long findGap(int T, int N){
if(T == 1){
return solve(N);
}
L = 0;
R = inf;
MinMax(L, R, &mn, &mx);
L = mn;
R = mx;
ans = (R - L + N - 2) / (N - 1);
while(L < R){
MinMax(L + 1, L + ans, &mn, &mx);
if(mx != -1){
L = mx;
continue;
}
MinMax(L + 1, L + (ans + 1) * 2, &mn, &mx);
while(mn == -1){
ans = (ans + 1) * 2 + 1;
MinMax(L + 1, L + (ans + 1) * 2, &mn, &mx);
}
ans = mn - L;
L = mx;
}
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
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 |
1 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 |
1 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 |
11 ms |
720 KB |
Output is correct |
17 |
Correct |
10 ms |
692 KB |
Output is correct |
18 |
Correct |
11 ms |
636 KB |
Output is correct |
19 |
Correct |
9 ms |
592 KB |
Output is correct |
20 |
Correct |
7 ms |
736 KB |
Output is correct |
21 |
Correct |
53 ms |
1864 KB |
Output is correct |
22 |
Correct |
36 ms |
1828 KB |
Output is correct |
23 |
Correct |
34 ms |
1864 KB |
Output is correct |
24 |
Correct |
38 ms |
1780 KB |
Output is correct |
25 |
Correct |
31 ms |
1852 KB |
Output is correct |
26 |
Correct |
37 ms |
1812 KB |
Output is correct |
27 |
Correct |
37 ms |
1816 KB |
Output is correct |
28 |
Correct |
36 ms |
1864 KB |
Output is correct |
29 |
Correct |
45 ms |
1748 KB |
Output is correct |
30 |
Correct |
31 ms |
1836 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 |
1 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 |
208 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 |
208 KB |
Output is correct |
15 |
Correct |
1 ms |
336 KB |
Output is correct |
16 |
Correct |
7 ms |
464 KB |
Output is correct |
17 |
Correct |
6 ms |
424 KB |
Output is correct |
18 |
Correct |
7 ms |
464 KB |
Output is correct |
19 |
Correct |
7 ms |
424 KB |
Output is correct |
20 |
Correct |
3 ms |
464 KB |
Output is correct |
21 |
Correct |
35 ms |
968 KB |
Output is correct |
22 |
Correct |
24 ms |
972 KB |
Output is correct |
23 |
Correct |
26 ms |
1060 KB |
Output is correct |
24 |
Correct |
29 ms |
1056 KB |
Output is correct |
25 |
Correct |
47 ms |
1096 KB |
Output is correct |
26 |
Correct |
25 ms |
1092 KB |
Output is correct |
27 |
Correct |
23 ms |
968 KB |
Output is correct |
28 |
Correct |
23 ms |
1088 KB |
Output is correct |
29 |
Correct |
23 ms |
1092 KB |
Output is correct |
30 |
Correct |
14 ms |
1068 KB |
Output is correct |
31 |
Correct |
1 ms |
208 KB |
Output is correct |
32 |
Correct |
0 ms |
208 KB |
Output is correct |