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;
long long findGap(int T, int n){
long long ans=0ll;
if(T==1){
long long l=0ll,r=1000000000000000000ll;
MinMax(l,r,&l,&r);
int temp=2;
for(int x=0;temp<n;x++){
long long newl=-1ll,newr=-1ll;
if(l+1ll<r-1ll)
MinMax(l+1ll,r-1ll,&newl,&newr);
if(newl!=-1ll){
ans=max(ans,max(newl-l,r-newr));
l=newl;
r=newr;
}
temp+=2;
}
if(n==2)
ans=r-l;
}else{
long long l=0ll,r=1000000000000000000ll;
MinMax(l,r,&l,&r);
int temp=2;
long long interv = (r-l)/(n-1ll),pre=-1ll;
ans=interv;
for(int x=0;x<n-1;x++){
long long a=l+x*interv+1ll,b=l+(x+1ll)*interv,c,d;
MinMax(a,b,&c,&d);
if(c!=-1ll){
ans=max(ans,d-c);
if(pre!=-1ll)
ans=max(ans,c-pre);
pre=d;
}
}
if(pre!=-1ll)
ans=max(ans,r-pre);
}
return ans;
}
Compilation message (stderr)
gap.cpp: In function 'long long int findGap(int, int)':
gap.cpp:27:13: warning: unused variable 'temp' [-Wunused-variable]
int temp=2;
^~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |