#include "gap.h"
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll findGap(int T, int n)
{
if(T == 1){
vector<ll> V;
ll l=1,r=1e18,mn,mx,ans=0;
while(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<V.size();i++) ans = max(ans,V[i]-V[i-1]);
return ans;
}
else{
vector<ll> V;
ll first,last,mn,mx,ans=0;
MinMax(1,1e18,&first,&last);
V.push_back(first), V.push_back(last);
ll dist = (last-first)/(n-1),pre = first+1;
while(pre < last && V.size() <= n){
MinMax(pre,pre+dist,&mn,&mx);
if(mn != -1 && mn != last) V.push_back(mn);
if(mx != -1 && mx != mn && mx != last) V.push_back(mx);
pre = pre+dist+1;
}
sort(V.begin(),V.end());
for(int i=1;i<V.size();i++) ans = max(ans,(ll)V[i]-V[i-1]);
return ans;
}
}
Compilation message
gap.cpp: In function 'long long int findGap(int, int)':
gap.cpp:10:24: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
10 | while(V.size() < n){
| ~~~~~~~~~^~~
gap.cpp:17:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
17 | for(int i=1;i<V.size();i++) ans = max(ans,V[i]-V[i-1]);
| ~^~~~~~~~~
gap.cpp:26:38: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
26 | while(pre < last && V.size() <= n){
| ~~~~~~~~~^~~~
gap.cpp:33:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
33 | for(int i=1;i<V.size();i++) ans = max(ans,(ll)V[i]-V[i-1]);
| ~^~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 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 |
336 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 |
12 ms |
844 KB |
Output is correct |
17 |
Correct |
10 ms |
848 KB |
Output is correct |
18 |
Correct |
14 ms |
808 KB |
Output is correct |
19 |
Correct |
10 ms |
848 KB |
Output is correct |
20 |
Correct |
9 ms |
848 KB |
Output is correct |
21 |
Correct |
43 ms |
2240 KB |
Output is correct |
22 |
Correct |
48 ms |
2252 KB |
Output is correct |
23 |
Correct |
45 ms |
2240 KB |
Output is correct |
24 |
Correct |
41 ms |
2252 KB |
Output is correct |
25 |
Correct |
38 ms |
2260 KB |
Output is correct |
26 |
Correct |
48 ms |
2332 KB |
Output is correct |
27 |
Correct |
43 ms |
2188 KB |
Output is correct |
28 |
Correct |
50 ms |
2200 KB |
Output is correct |
29 |
Correct |
40 ms |
2188 KB |
Output is correct |
30 |
Correct |
44 ms |
2232 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 |
1 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 |
1 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 |
2 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 |
14 ms |
816 KB |
Output is correct |
17 |
Correct |
14 ms |
848 KB |
Output is correct |
18 |
Correct |
14 ms |
892 KB |
Output is correct |
19 |
Correct |
13 ms |
812 KB |
Output is correct |
20 |
Correct |
6 ms |
520 KB |
Output is correct |
21 |
Correct |
53 ms |
2164 KB |
Output is correct |
22 |
Correct |
58 ms |
2208 KB |
Output is correct |
23 |
Correct |
58 ms |
2336 KB |
Output is correct |
24 |
Correct |
66 ms |
2176 KB |
Output is correct |
25 |
Correct |
55 ms |
2216 KB |
Output is correct |
26 |
Correct |
57 ms |
2192 KB |
Output is correct |
27 |
Correct |
61 ms |
2180 KB |
Output is correct |
28 |
Correct |
58 ms |
2256 KB |
Output is correct |
29 |
Correct |
65 ms |
2176 KB |
Output is correct |
30 |
Correct |
30 ms |
1444 KB |
Output is correct |
31 |
Correct |
1 ms |
208 KB |
Output is correct |
32 |
Correct |
0 ms |
208 KB |
Output is correct |