제출 #360290

#제출 시각아이디문제언어결과실행 시간메모리
360290joylintpGap (APIO16_gap)C++17
49.72 / 100
58 ms2072 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); if (T == 1) { vector<long long> a(N); a[0] = l, a[N - 1] = r; for (int i = 1; i <= N - i - 1; i++) MinMax(a[i - 1] + 1, a[N - i] - 1, &a[i], &a[N - i - 1]); long long mx = 0; for (int i = 0; i + 1 < N; i++) mx = max(mx, a[i + 1] - a[i]); return mx; } else { 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...