| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 1101316 | huyngo | Gap (APIO16_gap) | C++17 | 43 ms | 4100 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;
#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 || 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 x, y, res = 1;
MinMax(0, 1e18, &x, &y);
while (true) {
// find furest from x where [x+1, m] = -1
if (x >= y || x + res >= y) break;
ll u, v;
MinMax(x + 1, x + res, &u, &v);
if (u != -1) {
x = v;
continue;
}
ll l = x + res, r = y, sf = l;
while (l <= r) {
ll m = (l + r) / 2;
MinMax(x + 1, m, &u, &v);
if (u == -1) {
l = m + 1;
sf = max(sf, m);
res = max(res, m - x + 1);
}
else
r = m - 1;
}
x = sf + 1;
}
return res;
}
Compilation message (stderr)
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
