제출 #579911

#제출 시각아이디문제언어결과실행 시간메모리
579911stevancvGap (APIO16_gap)C++14
30 / 100
48 ms1884 KiB
#include <bits/stdc++.h> #include "gap.h" #define ll long long #define ld long double #define sp ' ' #define en '\n' #define smin(a, b) a = min(a, b) #define smax(a, b) a = max(a, b) using namespace std; const int N = 1e5 + 2; ll findGap(int t, int n) { if (t == 1 || t == 2) { vector<ll> a(n); ll mn = 0; ll mx = 1e18; for (int i = 0; i < n; i++) { if (i > n - i - 1) break; MinMax(mn, mx, &a[i], &a[n - i - 1]); mn = a[i] + 1; mx = a[n - i - 1] - 1; } ll ans = 0; for (int i = 1; i < n; i++) smax(ans, a[i] - a[i - 1]); return ans; } ll mn = 0; ll mx = 1e18; MinMax(0, 1e18, &mn, &mx); ll gap = (mx - mn + n - 2) / (n - 1); while (mn <= mx) { ll p, q, r, s; p = q = r = s = 0; if (mn + gap + 1 > mx - gap - 1) break; MinMax(mn + gap + 1, mx - gap - 1, &p, &q); if (p != -1) { if (mn + 1 <= p - gap - 1) MinMax(mn + 1, p - gap - 1, &r, &s); if (r != -1) smax(gap, p - r); else smax(gap, p - mn); s = -1; if (q + gap + 1 <= mx - 1) MinMax(q + gap + 1, mx - 1, &r, &s); if (s != -1) smax(gap, s - q); else smax(gap, mx - q); mn = p; mx = q; } else { MinMax(mn + 1, mn + gap, &p, &q); MinMax(mx - gap, mx - 1, &r, &s); if (q != -1) smax(mn, q); if (r != -1) smin(mx, r); smax(gap, mx - mn); break; } } return gap; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...