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>
// #include "grader.cpp"
using namespace std;
long long solve(int n){
long long mn,mx;
long long s=0,t=1e18;
vector<long long> arr;
vector<long long> a1;
while(int(arr.size())+int(a1.size())<n){
MinMax(s,t,&mn,&mx);
if(mn==-1)
break;
s=mn+1;
t=mx-1;
arr.push_back(mn);
a1.push_back(mx);
}
reverse(a1.begin(), a1.end());
for(long long i:a1)
arr.push_back(i);
long long g=0;
for(int i=1;i<arr.size();i++)
g=max(g,arr[i]-arr[i-1]);
return g;
}
long long findGap(int T, int N)
{
if(T==1)
return solve(N);
long long mn,mx;
long long s=0,t=1e18;
MinMax(s,t,&mn,&mx);
s=mn+1,t=mx;
long long gap=(t-s)/(N-1);
long long ans=0;
long long pre=mn;
while(s<t){
MinMax(s,min(s+gap,t),&mn,&mx);
if(mn==-1)
s+=gap;
else{
gap=max(gap,mn-pre);
s=mx+1;
pre=mx;
}
}
return gap;
}
Compilation message (stderr)
gap.cpp: In function 'long long int solve(int)':
gap.cpp:23:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
23 | for(int i=1;i<arr.size();i++)
| ~^~~~~~~~~~~
gap.cpp: In function 'long long int findGap(int, int)':
gap.cpp:36:12: warning: unused variable 'ans' [-Wunused-variable]
36 | long long ans=0;
| ^~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |