# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
624458 | socpite | 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>
using namespace std;
#define f first
#define s second
typedef long long ll;
ll ans = 0;
int n;
bool cmp(pair<ll, ll> a, pair<ll, ll> b)return b.f-a.f < b.s - a.s;
void solve(ll l, ll r, ll ele){
if(r-l <= ans)return;
ll dist;
if(ele >= 5)dist = min((r-l+ele*2)/ele*2, r-l-1);
else dist = (r-l+ele)/ele;
vector<pair<ll, ll>> A;
for(ll i = l; i <= r; i+=dist){
pair<ll, ll> tmp;
MinMax(i, min(i+dist-1, r), &tmp.f, &tmp.s);
if(tmp.s > 0){
ele -= 1+(tmp.f != tmp.s);
A.push_back(tmp);
}
}
for(int i = 1; i < A.size(); i++){
if(A[i-1].f != -1 && A[i].f != -1)ans = max(ans, A[i].f - A[i-1].s);
}
sort(A.begin(), A.end(), cmp);
for(auto v: A)solve(v.f, v.s, ele+1+(v.f != v.s));
}
long long findGap(int T, int N)
{
n = N;
solve(0, 1e18, N);
return ans;
}