Submission #347976

#TimeUsernameProblemLanguageResultExecution timeMemory
347976joylintpGap (APIO16_gap)C++17
19.72 / 100
50 ms1272 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); if (r - l == 2) { long long tl, tr; MinMax(l, l + 1, &tl, &tr); if (tr == l + 1) return ans = max(ans, 1LL); else return ans = max(ans, 2LL); } if (r - l == 3) { long long tl, tr; MinMax(l + 1, r - 1, &tl, &tr); if (tl == l + 1 && tr == r - 1) return ans = max(ans, 1LL); else if (tl == l + 1 || tr == r - 1) return ans = max(ans, 2LL); else return ans = max(ans, 3LL); } 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); } 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...