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;
const int N = 1e5 + 5;
int n;
long long a[N];
long long solve1() {
long long s = 0, t = 1e18;
long long mn, mx;
for (int i = 1; i <= (n + 1) / 2; ++i) {
if (s <= t) MinMax(s, t, &mn, &mx);
a[i] = mn; a[n - i + 1] = mx;
s = mn + 1, t = mx - 1;
}
long long ans = 0;
for (int i = 2; i <= n; ++i) ans = max(ans, a[i] - a[i - 1]);
return ans;
}
long long solve2() {
long long s = 0, t = 1e18;
long long mn, mx;
long long gap = (t - s + n - 2) / (n - 1);
int sz = 0;
for (long long i = s; i <= t; i += gap + 1) {
MinMax(i, i + gap, &mn, &mx);
a[++sz] = mn;
a[++sz] = mx;
}
long long ans = 0;
for (int i = 2; i <= sz; ++i) ans = max(ans, a[i] - a[i - 1]);
return ans;
}
long long findGap(int T, int _N) {
n = _N;
if (T == 1) return solve1();
else return solve2();
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |