이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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 || n==2) {
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];
}
bool full = true;
for (int i = 1; i <= n; i++) {
MinMax(l[i], r[i], &mn, &mx);
b[i] = {mn, mx};
if (mn == -1) full = false;
}
if (full) {
for (int i = 2; i < n; i++) {
ret = max(ret, b[i].first - b[i - 1].first);
}
} else {
for (int i = 2; i < n; i++) {
if (b[i - 1].first == -1 || b[i].first == -1) continue;
ret = max(ret, b[i].first - b[i - 1].second);
}
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... |