# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
560905 | duypd4206 | 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 "gap.h"
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn = 1e5 + 2;
ll findGap(int t, int n)
{
ll a[maxn];
if(t==1){
a[0] = -1;
a[n+1] = 2e18 + 1;
for(int i = 1, j = n; i <= j; i++,j--)
{
MinMax(a[i-1]+1,a[j+1]-1,&a[i],&a[j]);
}
ll res = 0;
for(int i = 1; i < n ; i++)
res = max(res,abs(a[i+1] - a[i]));
return res;
}
ll mn;
MinMax(-1,1e18,&mn,&mx);
if(n == 2) return mx - mn;
n--;
ll gap = (mx - mn) / n;
ll Pre = -1;
ll res = 0;
ll t1 = mn, t2 = mx;
for(ll be = t1; be < t2; be+= gap + 1)
{
MinMax(be, be + gap,&mn,&mx);
if(mn == -1)
continue;
if(Pre != -1)
res = max(res, mn - Pre);
Pre = mx;
}
return res;
}
//int main()
//{
//
//}