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>
#include "gap.h"
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;
ll a[100201];
ll l[100201], r[100201];
pll b[100201];
const ll inf = 1'000'000'000'000'000'000;
ll findGap(int T, int n) {
if (T == 1) {
ll L = 1, R = n, mn, mx;
ll low = 0, high = 1e18;
while (L < R) {
MinMax(low, high, &mn, &mx);
a[L++] = mn, a[R--] = mx;
low = mn + 1, high = mx - 1;
}
if (L == R) {
MinMax(low, high, &mn, &mx);
a[L] = mn;
}
ll ret = 0;
for (int i = 2; i <= n; i++) ret = max(ret, a[i] - a[i - 1]);
return ret;
}
ll mn, mx, ret = 0;
MinMax(0, inf, &mn, &mx);
a[1] = mn, a[n] = mx;
ll gap = (mx - mn + 1) / (n - 1);
for (ll i = a[1], cnt = 1; cnt < n; i += gap, cnt++) {
l[cnt] = i, r[cnt] = i + gap - 1;
if (cnt + 1 == n) r[cnt] = a[n];
}
for (int i = 1; i < n; i++) {
MinMax(l[i], r[i], &mn, &mx);
b[i] = {mn, mx};
}
ll bef = -1;
for (int i = 1; i < n; i++) {
if (b[i].first == -1) continue;
if (bef != -1) {
MinMax(bef, b[i].first, &mn, &mx);
ret = max(ret, mx - mn);
}
bef = b[i].second;
}
return ret;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |