# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
733933 | turbat | Gap (APIO16_gap) | C++14 | 44 ms | 1864 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 <algorithm>
#include <iostream>
using namespace std;
long long Subtask1(int T, int N) {
long long mn = 0, mx = 0, r = N, l = 1, a[N + 1], right = 1e18, left = 0,
k = 0;
while (r >= l) {
MinMax(left, right, &left, &right);
a[l] = left;
a[r] = right;
left++;
right--;
l++;
r--;
}
long long ans = 0;
for (int i = 1; i < N; i++) ans = max(ans, a[i + 1] - a[i]);
return ans;
}
long long findGap(int T, int N) {
if (T == 1) {
return Subtask1(T, N);
}
long long mn, mx, l, r;
MinMax(-1, 1e18 + 1, &mn, &mx);
long long gap = (mx - mn) / (N - 1), last = mn;
for (long long cur = mn + 1; cur < mx;) {
l = -1;
long long tmp = gap;
while (l == -1 && cur + tmp - gap <= mx) {
tmp += gap;
// cout << cur + tmp - gap << " " << cur + tmp << endl;
MinMax(cur + tmp - gap, cur + tmp, &l, &r);
}
if (l == -1) return gap;
gap = l - cur;
last = r;
cur = r + 1;
}
return gap;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |