Submission #347977

#TimeUsernameProblemLanguageResultExecution timeMemory
347977joylintpGap (APIO16_gap)C++17
19.72 / 100
57 ms1772 KiB
#include "gap.h" #include<bits/stdc++.h> using namespace std; long long findGap(int T, int N) { long long l, r, ans = 0; MinMax(0, 1000000000000000000, &l, &r); queue<pair<long long, long long>> q; q.push({l, r}); while (!q.empty()) { l = q.front().first, r = q.front().second, q.pop(); if (r - l <= ans) continue; if (r - l <= 1) ans = max(ans, r - l); else if (r - l == 2) { long long tl, tr; MinMax(l, l + 1, &tl, &tr); ans = max(ans, 2LL - (tr == l + 1)); } else if (r - l == 3) { long long tl, tr; MinMax(l + 1, r - 1, &tl, &tr); ans = max(ans, 3LL - (tl == l + 1) - (tr == r - 1)); } else { long long m = (l + r) / 2, ll, lr, rl, rr; MinMax(l + 1, m, &ll, &lr), MinMax(m + 1, r - 1, &rl, &rr); if (ll == -1 && rl == -1) ans = max(ans, r - l); else if (ll == -1) ans = max({ans, rl - l, r - rr}), q.push({rl, rr}); else if (rl == -1) ans = max({ans, ll - l, r - lr}), q.push({ll, lr}); else ans = max({ans, ll - l, rl - lr, r - rr}), q.push({ll, lr}), q.push({rl, rr}); } } return ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...