#include "gap.h"
#include <bits/stdc++.h>
using namespace std;
#define int long long
mt19937_64 rng(69420);
int rand(int l, int r){
return uniform_int_distribution<int>(l, r)(rng);
}
long long findGap(int32_t T, int32_t N)
{
int n=N;
if (T==1){
int pl=0, pr=1e18;
vector<int> a;
while (N>0){
int l, r;
MinMax(pl, pr, &l, &r);
a.push_back(l);
if (l!=r) a.push_back(r);
pl=l+1;
pr=r-1;
N-=2;
}
sort(a.begin(), a.end());
int ans=0;
for (int i=1; i<(int)a.size(); ++i) ans=max(ans, a[i]-a[i-1]);
return ans;
}
int l, r;
MinMax(0, 1e18, &l, &r);
if (N==2) return r-l;
if (r-l==2) return 1;
int min_ans=(r-l)/(n-1);
int ans=0;
int lst=l;
while (1){
int ll=l+1, rr=ll+min_ans-1;
if (rr>=r) break;
int tl, tr;
MinMax(ll, rr, &tl, &tr);
if (tr==-1) l=ll;
else{
ans=max(ans, tl-lst);
lst=tr;
l=tr;
}
}
return max(ans, r-lst);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
2392 KB |
Output is correct |
3 |
Correct |
0 ms |
2392 KB |
Output is correct |
4 |
Correct |
1 ms |
2392 KB |
Output is correct |
5 |
Correct |
0 ms |
2392 KB |
Output is correct |
6 |
Correct |
1 ms |
2392 KB |
Output is correct |
7 |
Correct |
1 ms |
2392 KB |
Output is correct |
8 |
Correct |
1 ms |
2392 KB |
Output is correct |
9 |
Correct |
1 ms |
2392 KB |
Output is correct |
10 |
Correct |
1 ms |
2392 KB |
Output is correct |
11 |
Correct |
1 ms |
2392 KB |
Output is correct |
12 |
Correct |
1 ms |
2400 KB |
Output is correct |
13 |
Correct |
1 ms |
2392 KB |
Output is correct |
14 |
Correct |
1 ms |
2392 KB |
Output is correct |
15 |
Correct |
1 ms |
2392 KB |
Output is correct |
16 |
Correct |
9 ms |
3008 KB |
Output is correct |
17 |
Correct |
8 ms |
2840 KB |
Output is correct |
18 |
Correct |
9 ms |
2844 KB |
Output is correct |
19 |
Correct |
8 ms |
2840 KB |
Output is correct |
20 |
Correct |
9 ms |
2836 KB |
Output is correct |
21 |
Correct |
33 ms |
3996 KB |
Output is correct |
22 |
Correct |
31 ms |
3988 KB |
Output is correct |
23 |
Correct |
35 ms |
3976 KB |
Output is correct |
24 |
Correct |
37 ms |
3996 KB |
Output is correct |
25 |
Correct |
28 ms |
3996 KB |
Output is correct |
26 |
Correct |
32 ms |
3976 KB |
Output is correct |
27 |
Correct |
31 ms |
3920 KB |
Output is correct |
28 |
Correct |
36 ms |
3976 KB |
Output is correct |
29 |
Correct |
38 ms |
3964 KB |
Output is correct |
30 |
Correct |
29 ms |
3828 KB |
Output is correct |
31 |
Correct |
1 ms |
2392 KB |
Output is correct |
32 |
Correct |
1 ms |
2392 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Execution timed out |
3065 ms |
2392 KB |
Time limit exceeded |
3 |
Execution timed out |
3032 ms |
2392 KB |
Time limit exceeded |
4 |
Execution timed out |
3040 ms |
2392 KB |
Time limit exceeded |
5 |
Correct |
1 ms |
2644 KB |
Output is correct |
6 |
Execution timed out |
3031 ms |
2396 KB |
Time limit exceeded |
7 |
Execution timed out |
3041 ms |
2392 KB |
Time limit exceeded |
8 |
Execution timed out |
3067 ms |
2392 KB |
Time limit exceeded |
9 |
Execution timed out |
3027 ms |
2552 KB |
Time limit exceeded |
10 |
Partially correct |
46 ms |
2392 KB |
Partially correct |
11 |
Execution timed out |
3016 ms |
2392 KB |
Time limit exceeded |
12 |
Execution timed out |
3069 ms |
2392 KB |
Time limit exceeded |
13 |
Execution timed out |
3033 ms |
2392 KB |
Time limit exceeded |
14 |
Execution timed out |
3066 ms |
2400 KB |
Time limit exceeded |
15 |
Correct |
1 ms |
2392 KB |
Output is correct |
16 |
Execution timed out |
3048 ms |
2568 KB |
Time limit exceeded |
17 |
Execution timed out |
3054 ms |
2588 KB |
Time limit exceeded |
18 |
Execution timed out |
3048 ms |
2588 KB |
Time limit exceeded |
19 |
Execution timed out |
3028 ms |
2588 KB |
Time limit exceeded |
20 |
Partially correct |
99 ms |
2576 KB |
Partially correct |
21 |
Execution timed out |
3067 ms |
2856 KB |
Time limit exceeded |
22 |
Execution timed out |
3040 ms |
2856 KB |
Time limit exceeded |
23 |
Execution timed out |
3051 ms |
3100 KB |
Time limit exceeded |
24 |
Execution timed out |
3012 ms |
2848 KB |
Time limit exceeded |
25 |
Correct |
36 ms |
2852 KB |
Output is correct |
26 |
Execution timed out |
3033 ms |
2860 KB |
Time limit exceeded |
27 |
Execution timed out |
3025 ms |
2852 KB |
Time limit exceeded |
28 |
Execution timed out |
3002 ms |
2788 KB |
Time limit exceeded |
29 |
Execution timed out |
3019 ms |
2856 KB |
Time limit exceeded |
30 |
Partially correct |
122 ms |
3044 KB |
Partially correct |
31 |
Execution timed out |
3059 ms |
2392 KB |
Time limit exceeded |
32 |
Execution timed out |
3012 ms |
2392 KB |
Time limit exceeded |