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>
using namespace std;
typedef long long llong;
int n;
const llong m = 1e18;
llong divpro(llong s, llong t) {
llong ret = 0;
llong a, b;
llong q = (t - s - 1) / n;
llong r = (t - s - 1) - q * n;
llong pree = s;
for (llong i = 0, j = s; i < n; ++i) {
llong dis = q + (i < r);
MinMax(j + 1, j + dis, &a, &b);
j += dis;
if (a == -1) continue;
ret = max(ret, a - pree);
pree = b;
}
return max(ret, t - pree);
}
long long findGap(int T, int N)
{
n = N;
llong s, t;
MinMax(0, m, &s, &t);
if (n == 2) return t - s;
n -= 2;
if (T == 1) {
llong ret = 0;
llong i = s, j = t;
while (n > 0) {
MinMax(i + 1, j - 1, &i, &j);
n -= 2;
ret = max(ret, max(t - j, i - s));
s = i; t = j;
}
return ret;
}
else {
return divpro(s, t);
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |