# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
21965 | RezwanArefin01 | 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>
using namespace std;
typedef long long ll;
long long findGap(int T, int N) {
if(T==1) {
ll pmn, pmx, mn, mx, ret = 0;
MinMax(0, (ll)1e18+10, &pmn, &pmx);
for(int i=1; i<(N+1)/2; i++) {
MinMax(pmn+1, pmx-1, &mn, &mx);
ret = max(ret, mn - pmn);
ret = max(ret, pmx - mx);
pmn = mn, pmx = mx;
} ret = max(ret, pmx - pmn);
return ret;
} else {
ll st, ed, ret = 0;
MinMax(0, (ll)2e18+10, &st, &ed);
if(N == 2) return ed - st;
ll gap = (ed - st + N - 1) / N, prev = st;
for(ll i=st+1, j=i + gap, b = 1; b<N; i=j+1, j=i+gap) {
j = min(j, ed-1);
if(i > j) break;
ll mn, mx;
MinMax(i, j, &mn, &mx);
if(mn != -1) {
ret = max(ret, mn - prev);
prev = mx;
}
} return max(ret, ed - prev);
}
}