#include "gap.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e18;
long long findGap(int t, int n){
if(t == 1){
ll l = 0 , r = INF , ansl , ansr , res = 0;
vector<ll> ans;
for(int i = 0 ; i < (n + 1) / 2 ; i++){
MinMax(l , r , &ansl , &ansr);
ans.push_back(ansl);
ans.push_back(ansr);
l = ansl + 1;
r = ansr - 1;
}
sort(ans.begin() , ans.end());
for(int i = 0 ; i + 1 < ans.size() ; i++){
res = max(res , ans[i + 1] - ans[i]);
}
return res;
}
ll l , r , len , x;
MinMax(0 , INF , &l , &r);
len = r - l; x = (len + n - 2) / (n - 1);
vector<ll> ans = {l , r};
for(int i = 0 ; i < n - 1 ; i++){
ll ql = l + i * x , qr = l + (i + 1) * x;
ll ansl , ansr;
MinMax(ql , qr - 1 , &ansl , &ansr);
if(ansl == -1) continue;
ans.push_back(ansl);
ans.push_back(ansr);
}
sort(ans.begin() , ans.end());
ll res = 0;
for(int i = 0 ; i + 1 < ans.size() ; i++){
res = max(res , ans[i + 1] - ans[i]);
}
//cout << len << endl;
return res;
}
Compilation message
gap.cpp: In function 'long long int findGap(int, int)':
gap.cpp:22:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
22 | for(int i = 0 ; i + 1 < ans.size() ; i++){
| ~~~~~~^~~~~~~~~~~~
gap.cpp:41:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
41 | for(int i = 0 ; i + 1 < ans.size() ; i++){
| ~~~~~~^~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
0 ms |
364 KB |
Output is correct |
3 |
Correct |
0 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
0 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
0 ms |
364 KB |
Output is correct |
10 |
Correct |
0 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
13 ms |
1024 KB |
Output is correct |
17 |
Correct |
14 ms |
876 KB |
Output is correct |
18 |
Correct |
16 ms |
876 KB |
Output is correct |
19 |
Correct |
13 ms |
876 KB |
Output is correct |
20 |
Correct |
10 ms |
876 KB |
Output is correct |
21 |
Correct |
67 ms |
2276 KB |
Output is correct |
22 |
Correct |
51 ms |
2276 KB |
Output is correct |
23 |
Correct |
61 ms |
2288 KB |
Output is correct |
24 |
Correct |
50 ms |
2276 KB |
Output is correct |
25 |
Correct |
45 ms |
2276 KB |
Output is correct |
26 |
Correct |
56 ms |
2276 KB |
Output is correct |
27 |
Correct |
51 ms |
2276 KB |
Output is correct |
28 |
Correct |
62 ms |
2276 KB |
Output is correct |
29 |
Correct |
56 ms |
2276 KB |
Output is correct |
30 |
Correct |
43 ms |
2228 KB |
Output is correct |
31 |
Correct |
1 ms |
364 KB |
Output is correct |
32 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
0 ms |
364 KB |
Output is correct |
3 |
Correct |
0 ms |
364 KB |
Output is correct |
4 |
Correct |
0 ms |
364 KB |
Output is correct |
5 |
Correct |
0 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
0 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
16 |
Correct |
16 ms |
876 KB |
Output is correct |
17 |
Correct |
16 ms |
876 KB |
Output is correct |
18 |
Correct |
16 ms |
876 KB |
Output is correct |
19 |
Correct |
16 ms |
876 KB |
Output is correct |
20 |
Correct |
7 ms |
492 KB |
Output is correct |
21 |
Correct |
65 ms |
2320 KB |
Output is correct |
22 |
Correct |
65 ms |
2328 KB |
Output is correct |
23 |
Correct |
71 ms |
2276 KB |
Output is correct |
24 |
Correct |
71 ms |
2276 KB |
Output is correct |
25 |
Correct |
63 ms |
3296 KB |
Output is correct |
26 |
Correct |
65 ms |
2404 KB |
Output is correct |
27 |
Correct |
64 ms |
2300 KB |
Output is correct |
28 |
Correct |
65 ms |
2276 KB |
Output is correct |
29 |
Correct |
66 ms |
2276 KB |
Output is correct |
30 |
Correct |
34 ms |
1516 KB |
Output is correct |
31 |
Correct |
1 ms |
364 KB |
Output is correct |
32 |
Correct |
0 ms |
364 KB |
Output is correct |