# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
142983 | IC_COLDSTOP | 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>
using namespace std;
#define ll long long
#define int ll
#define MP make_pair
#define pb push_back
#define F first
#define S second
#define REP(i,a,b) for(int i=a; i<b; i++)
#define pii pair<int,int>
#include "gap.h"
const int MX=1e5+3;
int n;
int ANS1(){
int l=0, r=1e18, st=0, en=n-1, arr[MX];
while(st<=en){
ll a,b; MinMax(l,r,&a,&b);
arr[st++]=a, arr[en--]=b;
}
int cnt=0;
REP(i,0,n-1) cnt=max(cnt, arr[i+1]-arr[i]);
return cnt;
}
int ANS2(){
ll a,b; MinMax(0,1e18,&a,&b);
int cnt=(b-a+(n-2))/(n-1), ans=cnt, lst=a, tmp=0;
while(lst<=b){
ll l,r; MinMax(lst+tmp+1,lst+tmp+cnt,&l,&r);
if(l==-1) tmp+=cnt;
else{
ans=max(ans, lst-l);
lst=r;
tmp=0;
}
}
return ans;
}
ll findGap(int t,int n){
::n=n;
if(t==1) return ANS1();
return ANS2();
}