# | TimeUTC-0 | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
844820 | dutinmeow | 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>
template<typename T>
bool chmax(T &a, T b) {
if (a >= b)
return false;
a = b;
return true;
}
long long findGap(int t, int n) {
if (t == 1) {
std::vector<long long> a;
a.reserve(n);
long long bl = 0, br = 1e18;
for (int i = 0; i < (n + 1) / 2; i++) {
long long al, ar;
MinMax(bl, br, &al, &ar);
a.push_back(al);
a.push_back(ar);
bl = al + 1, br = ar - 1;
}
if ((int)a.size() > n)
a.pop_back();
std::sort(a.begin(), a.end());
long long r = 0;
for (int i = 1; i < n; i++)
chmax(r, a[i] - a[i - 1]);