#include "bits/stdc++.h"
#include "gap.h"
using namespace std;
using ll = long long;
long long findGap(int T, int N)
{
ll cep,sag;
MinMax(1,(ll)1e18,&cep,&sag);
if(T == 1){
vector<ll>v;
v.push_back(cep);
v.push_back(sag);
while(cep < sag - 1 and (int)v.size() < N){
ll cp,sg;
MinMax(cep+1,sag-1,&cp,&sg);
if(cp != -1){
v.push_back(cp);
if(cp == sg) break;
v.push_back(sg);
cep = cp;
sag = sg;
}
}
sort(v.begin(),v.end());
ll ans = 0;
for(int i = 1;i < (int)v.size();i++) ans = max(ans,v[i] - v[i - 1]);
return ans;
}
ll sz = (sag - cep + N - 2) / (N - 1);
ll ans = sz,lst = cep;
ll cp,sg,nw = cep;
for(ll i = cep;i + sz < sag;i += sz + 1){
MinMax(i,i + sz,&cp,&sg);
if(cp != -1){
ans = max(ans,cp - lst);
lst = sg;
}
nw = i + sz + 1;
}
MinMax(nw,sag,&cp,&sg);
if(cp != -1) ans = max(ans,cp - lst);
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 |
0 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 |
0 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 |
10 ms |
848 KB |
Output is correct |
17 |
Correct |
10 ms |
916 KB |
Output is correct |
18 |
Correct |
10 ms |
848 KB |
Output is correct |
19 |
Correct |
10 ms |
824 KB |
Output is correct |
20 |
Correct |
8 ms |
848 KB |
Output is correct |
21 |
Correct |
38 ms |
2144 KB |
Output is correct |
22 |
Correct |
42 ms |
2248 KB |
Output is correct |
23 |
Correct |
41 ms |
2324 KB |
Output is correct |
24 |
Correct |
38 ms |
2188 KB |
Output is correct |
25 |
Correct |
36 ms |
2148 KB |
Output is correct |
26 |
Correct |
46 ms |
2240 KB |
Output is correct |
27 |
Correct |
39 ms |
2240 KB |
Output is correct |
28 |
Correct |
39 ms |
2204 KB |
Output is correct |
29 |
Correct |
40 ms |
2204 KB |
Output is correct |
30 |
Correct |
33 ms |
2240 KB |
Output is correct |
31 |
Correct |
0 ms |
208 KB |
Output is correct |
32 |
Correct |
1 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 |
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 |
1 ms |
208 KB |
Output is correct |
9 |
Correct |
1 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 |
336 KB |
Output is correct |
15 |
Correct |
1 ms |
208 KB |
Output is correct |
16 |
Correct |
12 ms |
476 KB |
Output is correct |
17 |
Correct |
13 ms |
512 KB |
Output is correct |
18 |
Correct |
12 ms |
428 KB |
Output is correct |
19 |
Correct |
12 ms |
424 KB |
Output is correct |
20 |
Correct |
6 ms |
512 KB |
Output is correct |
21 |
Correct |
52 ms |
1084 KB |
Output is correct |
22 |
Correct |
50 ms |
1184 KB |
Output is correct |
23 |
Correct |
50 ms |
1060 KB |
Output is correct |
24 |
Correct |
49 ms |
960 KB |
Output is correct |
25 |
Correct |
43 ms |
1080 KB |
Output is correct |
26 |
Correct |
52 ms |
1060 KB |
Output is correct |
27 |
Correct |
50 ms |
1068 KB |
Output is correct |
28 |
Correct |
49 ms |
1084 KB |
Output is correct |
29 |
Correct |
49 ms |
1084 KB |
Output is correct |
30 |
Correct |
24 ms |
976 KB |
Output is correct |
31 |
Correct |
0 ms |
208 KB |
Output is correct |
32 |
Correct |
0 ms |
208 KB |
Output is correct |