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>
typedef long long llint;
const llint maxn = 2e18;
using namespace std;
long long findGap(int t, int n) {
llint sol = 0;
if (t == 1) {
llint a, b;
MinMax(0, maxn, &a, &b);
while (n >= 2) {
if (n == 2) sol = max(sol, b - a);
n -= 2;
llint ta, tb;
MinMax(a + 1, b - 1, &ta, &tb);
sol = max(sol, max(ta - a, b - tb));
a = ta, b = tb;
}
} else {
llint a, b;
MinMax(0, maxn, &a, &b);
llint delta = b - a;
llint mini = delta / n;
llint las = a;
for (llint t = a + 1; t < b; t += mini) {
llint ta, tb;
if (t + mini >= b) {
if (t >= b - 1) break;
MinMax(t, b - 1, &ta, &tb);
} else MinMax(t, t + mini - 1, &ta, &tb);
if (ta > -1) {
sol = max(sol, ta - las);
las = tb;
}
}
sol = max(sol, b - las);
}
return sol;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |