# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
556893 | Sharky | Gap (APIO16_gap) | C++17 | 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;
long long findGap(int T, int N) {
if (T == 1) {
pair<long long, long long> range = {1, inf};
long long cnt = 0, mn, mx;
vector<long long> a;
for (long long i = 0; i < (N + 1) / 2; i++) {
MinMax(range.first, range.second, &mn, &mx);
range = {mn + 1, mx - 1};
a.pb(mn); a.pb(mx);
}
sort(all(a));
long long ans = 0;
for (long long i = 1; i < N; i++) ans = max(ans, a[i] - a[i - 1]);
return ans;
}
long long L = 1, R = inf, mn, mx;
MinMax(L, R, &mn, &mx);
long long hole = (mx - mn - 1 + (N - 1)) / (N - 1);
long long MN, MX, i, ans = hole, lst = mn;
for (i = mn; i + hole < mx; i += hole + 1) {
MinMax(i, i + hole, &MN, &MX);
if (MN != -1) ans = max(ans, MN - lst), lst = MX;
}
MinMax(i, mx, &MN, &MX);
if (MN != -1) ans = max(ans, MN - lst);
return ans;
}