# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
614094 | sword060 | Gap (APIO16_gap) | C++17 | 0 ms | 0 KiB |
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 <bits/stdc++.h>
#include "gap.h"
using namespace std;
vector<long long>a;
int rec(long long l,long long r,long long x){
if(l>r||x<=0)return 0;
long long c,v;
MinMax(l,r,&c,&v);
if(c==-1)return 0;
a.push_back(c);a.push_back(v);
if(c==v||c==v-1)return 2;
int ret=2;
ret+=rec(c+1,(c+v)/2,x-2)+2;
ret+=rec((c+v)/2+1,v-1,x-ret)+2;
return ret;
}
long long findGap(int q,int x){
if(q==2)rec(0,1e18,x);
else{
long long c=0,v=1e18,zz=x;
while(zz&&c<=v){
long long l,r;
MinMax(c,v,&l,&r);
if(l==-1)break;
a.push_back(l);if(l!=r)a.push_back(r);
c=l+1;v=r-1;zz-=2;
}
}
sort(a.begin(),a.end());
long long ret=0;
for(int i=0;i<(int)a.size()-1;i++)ret=max(ret,a[i+1]-a[i]);
return ret;
}