#include <bits/stdc++.h>
using namespace std;
#include "gap.h"
typedef long long ll;
typedef vector<ll> vl;
#define all(x) x.begin(),x.end()
#define pb push_back
ll ceil(ll a,ll b){return (a+b-1)/b;}
ll findGap(int T, int n){
ll L=0,R=1e18;
vl a;
if(T==1){
int i=0;
while(2*i<n){
MinMax(L,R,&L,&R);
a.pb(L);
a.pb(R);
L++,R--;
i++;
}
if(L==R && L!=-1)
a.pb(L);
ll ans=0;
sort(all(a));
for(int i=0; i+1<a.size(); i++)
ans=max(ans,a[i+1]-a[i]);
return ans;
}
MinMax(0,1e18,&L,&R);
ll block=ceil(R-L+1,n);
ll ans=0;
multiset<ll>s={L};
a={L,R};
for(int i=0; i<n; i++){
ll l=max(L+1,L+i*block);
ll r=min(R-1,l+block-1);
if(i==n-1)
s.insert(R);
while(l<r){
MinMax(l,r,&l,&r);
if(l==-1)break;
a.pb(l);
a.pb(r);
s.insert(l);
s.insert(r);
ans=max(ans,r-(*(--s.lower_bound(r))));
if(s.upper_bound(l)!=s.end())
ans=max(ans,*s.upper_bound(l)-l);
l++,r--;
if(r-l<=ans)break;
}
if(l==r && l!=-1)
a.pb(l);
}
sort(all(a));
for(int i=0; i+1<a.size(); i++)
ans=max(ans,a[i+1]-a[i]);
return ans;
}
Compilation message
gap.cpp: In function 'll findGap(int, int)':
gap.cpp:29:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
29 | for(int i=0; i+1<a.size(); i++)
| ~~~^~~~~~~~~
gap.cpp:69:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
69 | for(int i=0; i+1<a.size(); i++)
| ~~~^~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
200 KB |
Output is correct |
2 |
Correct |
0 ms |
200 KB |
Output is correct |
3 |
Correct |
0 ms |
200 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
200 KB |
Output is correct |
6 |
Correct |
0 ms |
200 KB |
Output is correct |
7 |
Correct |
0 ms |
200 KB |
Output is correct |
8 |
Correct |
1 ms |
200 KB |
Output is correct |
9 |
Correct |
1 ms |
200 KB |
Output is correct |
10 |
Correct |
0 ms |
200 KB |
Output is correct |
11 |
Correct |
1 ms |
328 KB |
Output is correct |
12 |
Correct |
1 ms |
328 KB |
Output is correct |
13 |
Correct |
1 ms |
328 KB |
Output is correct |
14 |
Correct |
1 ms |
328 KB |
Output is correct |
15 |
Correct |
1 ms |
328 KB |
Output is correct |
16 |
Correct |
11 ms |
888 KB |
Output is correct |
17 |
Correct |
9 ms |
888 KB |
Output is correct |
18 |
Correct |
10 ms |
840 KB |
Output is correct |
19 |
Correct |
11 ms |
812 KB |
Output is correct |
20 |
Correct |
8 ms |
840 KB |
Output is correct |
21 |
Correct |
38 ms |
2196 KB |
Output is correct |
22 |
Correct |
38 ms |
2192 KB |
Output is correct |
23 |
Correct |
38 ms |
2244 KB |
Output is correct |
24 |
Correct |
38 ms |
2132 KB |
Output is correct |
25 |
Correct |
35 ms |
2192 KB |
Output is correct |
26 |
Correct |
39 ms |
2196 KB |
Output is correct |
27 |
Correct |
38 ms |
2196 KB |
Output is correct |
28 |
Correct |
45 ms |
2232 KB |
Output is correct |
29 |
Correct |
38 ms |
2196 KB |
Output is correct |
30 |
Correct |
34 ms |
2244 KB |
Output is correct |
31 |
Correct |
0 ms |
200 KB |
Output is correct |
32 |
Correct |
0 ms |
200 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
200 KB |
Output is correct |
2 |
Correct |
1 ms |
200 KB |
Output is correct |
3 |
Correct |
0 ms |
200 KB |
Output is correct |
4 |
Correct |
0 ms |
200 KB |
Output is correct |
5 |
Correct |
0 ms |
200 KB |
Output is correct |
6 |
Correct |
0 ms |
200 KB |
Output is correct |
7 |
Correct |
0 ms |
200 KB |
Output is correct |
8 |
Correct |
1 ms |
200 KB |
Output is correct |
9 |
Correct |
0 ms |
328 KB |
Output is correct |
10 |
Correct |
0 ms |
200 KB |
Output is correct |
11 |
Correct |
1 ms |
328 KB |
Output is correct |
12 |
Correct |
1 ms |
328 KB |
Output is correct |
13 |
Correct |
1 ms |
328 KB |
Output is correct |
14 |
Correct |
1 ms |
328 KB |
Output is correct |
15 |
Correct |
1 ms |
456 KB |
Output is correct |
16 |
Correct |
19 ms |
2180 KB |
Output is correct |
17 |
Correct |
20 ms |
2228 KB |
Output is correct |
18 |
Correct |
20 ms |
2112 KB |
Output is correct |
19 |
Correct |
21 ms |
2140 KB |
Output is correct |
20 |
Correct |
5 ms |
456 KB |
Output is correct |
21 |
Correct |
90 ms |
7940 KB |
Output is correct |
22 |
Correct |
88 ms |
7948 KB |
Output is correct |
23 |
Correct |
90 ms |
7952 KB |
Output is correct |
24 |
Correct |
90 ms |
7968 KB |
Output is correct |
25 |
Correct |
106 ms |
11988 KB |
Output is correct |
26 |
Correct |
100 ms |
7956 KB |
Output is correct |
27 |
Correct |
88 ms |
7928 KB |
Output is correct |
28 |
Correct |
88 ms |
7880 KB |
Output is correct |
29 |
Correct |
91 ms |
7952 KB |
Output is correct |
30 |
Correct |
30 ms |
2056 KB |
Output is correct |
31 |
Correct |
0 ms |
200 KB |
Output is correct |
32 |
Correct |
0 ms |
200 KB |
Output is correct |