Submission #347971

#TimeUsernameProblemLanguageResultExecution timeMemory
347971joylintpGap (APIO16_gap)C++17
19.72 / 100
53 ms1292 KiB
#include "gap.h" #include<bits/stdc++.h> using namespace std; long long ans = 0; long long dfs(long long l, long long r) { if (r - l <= ans) return ans; if (r - l <= 1) return ans = max(ans, r - l), r - l; if (r - l == 2) { long long tl, tr; MinMax(l, l + 1, &tl, &tr); if (tr == l + 1) return ans = max(ans, 1LL), 1; else return ans = max(ans, 2LL), 2; } long long m = (l + r) / 2, ll, lr, rl, rr; MinMax(l + 1, m, &ll, &lr), MinMax(m + 1, r - 1, &rl, &rr); long long ret = ans; if (ll == -1 && rr == -1) ret = r - l; else if (ll == -1) { ret = max({ret, rl - l, r - rr}); if (rr - rl > ret) ret = max(ret, dfs(rl, rr)); } else if (rr == -1) { ret = max({ret, ll - l, r - lr}); if (lr - ll > ret) ret = max(ret, dfs(ll, lr)); } else { ret = max({ret, ll - l, rl - lr, r - rr}); if (lr - ll > ret) ret = max(ret, dfs(ll, lr)); if (rr - rl > ret) ret = max(ret, dfs(rl, rr)); } return ans = max(ans, ret), ret; } long long findGap(int T, int N) { long long l, r; MinMax(0, 1000000000000000000, &l, &r); return dfs(l, r); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...