# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1111122 | imarn | Gap (APIO16_gap) | C++14 | 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>
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define plx pair<ll,int>
#define f first
#define s second
#define pb push_back
#define all(x) x.begin(),x.end()
#define vi vector<int>
#define vvi vector<vi>
#define pp pair<ll,int>
#define ub(x,i) upper_bound(all(x),i)-x.begin()
#include "gap.h"
using namespace std;
long long cal1(int n){
ll a[n];
ll l=0,r=n-1;
ll mn=0,mx=0;
ll tl=0,tr=1e18;
while(l<=r){
MinMax(tl,tr,a[l],a[r]);
tl=a[l]+1,tr=a[r]-1;
l++,r--;
}ll rs=0;
for(int i=1;i<n;i++)rs=max(rs,a[i]-a[i-1]);
return rs;
}
ll cal2(int n){
ll mn,mx;
ll tl=0,tr=1e18;
MinMax(tl,tr,mn,mx);
ll ans = (mx-mn-1)/(n-1)+1;
ll cl=-1,cr=-1;
ll rl = mn+1,rr=mn+ans;
while(1){
MinMax(rl,rr,cl,cr);
if(cl==-1){
rl = rr+1;
rr = rr+ans;
}
else {
ans = max(ans,cl-mn);
mn=cr;
rl=rr+1;
rr=rr+ans;
if(cr==mx)break;
}
}return ans;
}
long long findGap(int T, int N)
{
if(T==1)return cal1(N);
else return cal2(N);
}
/*int main(){m=5;
b[0]=2;
b[1]=3;
b[2]=6;
b[3]=500;
b[4]=10000;
cout<<findGap(2,5);
}*/