# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
238081 | DS007 | 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;
void MinMax(long long s, long long t, long long &mn, long long &mx);
long long solve1(int n) {
set<long long> s;
long long l = 0, h = 1e18;
while (s.size() != n) {
long long mn = -1, mx = -1;
MinMax(l, h, mn, mx);
l = mn + 1, h = mx - 1;
s.insert(mn);
s.insert(mx);
}
long long last = 1e18, ans = 0;
for (auto i : s) {
ans = max(ans, i - last);
last = i;
}
return ans;
}
long long solve2(int n) {
long long mn = -1, mx = -1, l = 0, h = 1e18, tm1 = -1, tm2 = -1;
MinMax(l, h, mn, mx);
if (n == 2)
return mx - mn;
long long m = (mx - mn) / (n - 2), last = 1e18, ans = 0;
for (long long i = mn; i < mx; i += m) {
MinMax(i, i + m, tm1, tm2);
ans = max(ans, tm1 - last);
last = tm2;
}
return ans;
}
long long solve(int t, int n) {
if (t == 1)
return solve1(n);
else
return solve2(n);
}