#include<bits/stdc++.h>
using namespace std;
#include "gap.h"
long long findGap(int T, int N){
if(T==1){
long long l=1,r=1e18,res=0;
long long mn,mx;
vector<long long>v;
while(l<=r&&v.size()<N){
MinMax(l,r,&mn,&mx);
v.push_back(mn);
if(mx!=mn)v.push_back(mx);
l=mn+1;
r=mx-1;
}
sort(v.begin(),v.end());
for(int i=1;i<N;i++)res=max(res,v[i]-v[i-1]);
return res;
}else{
long long l=1,r=1e18,res=0,mn,mx,x,y,i;
MinMax(l,r,&mn,&mx);
long long bsz=(mx-mn+N-2)/(N-1);
res=bsz;l=mn;
for(i=mn;i+bsz<mx;i+=bsz+1){
MinMax(i,i+bsz,&x,&y);
if(~x){
res=max(res,x-l);
l=y;
}
}
MinMax(i,mx,&x,&y);
if(~x)res=max(res,x-l);
return res;
}
return 0;
}
Compilation message
gap.cpp: In function 'long long int findGap(int, int)':
gap.cpp:9:29: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
9 | while(l<=r&&v.size()<N){
| ~~~~~~~~^~
# |
결과 |
실행 시간 |
메모리 |
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 |
1 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 |
1 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 |
440 KB |
Output is correct |
16 |
Correct |
11 ms |
848 KB |
Output is correct |
17 |
Correct |
9 ms |
828 KB |
Output is correct |
18 |
Correct |
10 ms |
848 KB |
Output is correct |
19 |
Correct |
10 ms |
848 KB |
Output is correct |
20 |
Correct |
8 ms |
848 KB |
Output is correct |
21 |
Correct |
45 ms |
2200 KB |
Output is correct |
22 |
Correct |
42 ms |
2200 KB |
Output is correct |
23 |
Correct |
38 ms |
2212 KB |
Output is correct |
24 |
Correct |
37 ms |
2232 KB |
Output is correct |
25 |
Correct |
45 ms |
2204 KB |
Output is correct |
26 |
Correct |
37 ms |
2248 KB |
Output is correct |
27 |
Correct |
38 ms |
2156 KB |
Output is correct |
28 |
Correct |
45 ms |
2204 KB |
Output is correct |
29 |
Correct |
38 ms |
2220 KB |
Output is correct |
30 |
Correct |
41 ms |
2228 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 |
1 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 |
208 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 |
516 KB |
Output is correct |
17 |
Correct |
12 ms |
424 KB |
Output is correct |
18 |
Correct |
13 ms |
464 KB |
Output is correct |
19 |
Correct |
12 ms |
520 KB |
Output is correct |
20 |
Correct |
6 ms |
464 KB |
Output is correct |
21 |
Correct |
53 ms |
1088 KB |
Output is correct |
22 |
Correct |
48 ms |
1084 KB |
Output is correct |
23 |
Correct |
46 ms |
1064 KB |
Output is correct |
24 |
Correct |
51 ms |
968 KB |
Output is correct |
25 |
Correct |
45 ms |
1080 KB |
Output is correct |
26 |
Correct |
47 ms |
1024 KB |
Output is correct |
27 |
Correct |
53 ms |
1056 KB |
Output is correct |
28 |
Correct |
46 ms |
1056 KB |
Output is correct |
29 |
Correct |
55 ms |
1064 KB |
Output is correct |
30 |
Correct |
23 ms |
1084 KB |
Output is correct |
31 |
Correct |
0 ms |
208 KB |
Output is correct |
32 |
Correct |
0 ms |
208 KB |
Output is correct |