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;
#define ll long long
long long findGap(int T, int N) {
if (T == 1) {
vector<ll> a;
auto calc = [&](auto self, ll l, ll r) -> void {
if (l > r || (int)a.size() == N) return;
ll x, y;
MinMax(l, r, &x, &y);
if (x != -1)
a.push_back(x);
if (y != x)
a.push_back(y);
self(self, x + 1, y - 1);
};
calc(calc, 0, 1e18);
sort(a.begin(), a.end());
ll res = a[1] - a[0];
for (int i = 2; i < N; ++i)
res = max(res, a[i] - a[i - 1]);
return res;
}
ll mn, mx;
MinMax(1, 1e18, &mn, &mx);
ll step = (mx - mn) / (N - 1);
ll ans = step, x, y, l = mn, i;
for (i = mn; i + step < mx; i += step + 1) {
MinMax(i, i + step, &x, &y);
if (x != -1) {
ans = max(ans, x - l);
l = y;
}
}
MinMax(i, mx, &x, &y);
if (x != -1) ans = max(ans, x - l);
return ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |