This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "gap.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
long long findGap(int T, int N)
{
if(T==1){
ll l = 0,r = 1e18;
vector<ll>a,b;
while(r>=l && a.size() + b.size() < N){
ll mn,mx;
MinMax(l,r,&mn,&mx);
if(mn==-1)break;
if(mn==mx){
a.push_back(mn);
break;
}else{
a.push_back(mn);
b.push_back(mx);
}
l = mn+1;
r = mx-1;
}
reverse(b.begin(),b.end());
for(auto x:b)a.push_back(x);
ll ans = 0;
for(int i=0;i+1<N;i++)ans = max(ans,a[i+1]-a[i]);
return ans;
}
else{
ll mn,mx;
MinMax(0,1e18,&mn,&mx);
ll x = (mx-mn+N-1) /(N-1);
vector<ll>a;
for(ll l=mn;l<=mx;){
ll c,d;
MinMax(l,min(l+x-1,mx),&c,&d);
l = max(d+1,l+x);
if(c == -1)continue;
a.push_back(c);
a.push_back(d);
}
ll ans = 0;
for(int i=0;i+1<(int)(a.size());i++)ans = max(ans,a[i+1]-a[i]);
return ans;
}
}
Compilation message (stderr)
gap.cpp: In function 'long long int findGap(int, int)':
gap.cpp:10:37: 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(r>=l && a.size() + b.size() < N){
| ~~~~~~~~~~~~~~~~~~~~^~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |