Submission #32039

#TimeUsernameProblemLanguageResultExecution timeMemory
32039imeimi2000Gap (APIO16_gap)C++14
100 / 100
83 ms4236 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...