제출 #40810

#제출 시각아이디문제언어결과실행 시간메모리
40810ssnsarang2023Gap (APIO16_gap)C++14
100 / 100
79 ms2284 KiB
#include <bits/stdc++.h> #include "gap.h" using namespace std; typedef long long ll; //#define DEBUG #ifdef DEBUG int n = 5; ll arr[105] = {2, 3, 6, 8, 12}; void MinMax(ll x, ll y, ll *mn, ll *mx) { for (int i = 0; i < n; ++i) if (arr[i] >= x) { (*mn) = arr[i]; break; } for (int i = n - 1; i >= 0; --i) if (arr[i] <= y) { (*mx) = arr[i]; break; } if ((*mx) < (*mn)) (*mx) = (*mn) = -1; } #endif ll findGap(int _t, int _n) { ll n = _n; ll mn = 1, mx = (ll)1e18; MinMax(mn, mx, &mn, &mx); if (_t == 2) { ll d = (mx - mn) / (n - 1ll) + (ll)((mx - mn) % (n - 1ll) != 0ll), pre = mn; ll pstep = mn, step = mn + d - 1, gap = 0; while (1) { ll mntmp = -1, mxtmp = -1; if (pstep < min(mx - 1ll, step)) MinMax(pstep + 1ll, min(mx - 1ll, step), &mntmp, &mxtmp); if (step >= mx - 1ll) { gap = max(gap, mntmp - pre); if (mxtmp != -1ll) gap = max(gap, mx - mxtmp); else gap = max(gap, mx - pre); break; } else if (mntmp != -1ll) gap = max(gap, mntmp - pre); pre = max(pre, mxtmp), pstep = step, step += d; } return gap; } else { vector<ll> a; a.resize(_n); a[0] = mn, a[n - 1] = mx; int lo = 0, hi = _n - 1; while (hi - lo > 1) { MinMax(a[lo] + 1ll, a[hi] - 1ll, &mn, &mx); ++lo, --hi; a[lo] = mn, a[hi] = mx; } ll gap = 0; int pos = 0; for (int i = 0; i < _n - 1; ++i) { if (gap < a[i + 1] - a[i]) gap = a[i + 1] - a[i], pos = i; } return gap; } return 0ll; } #ifdef DEBUG int main() { freopen("input.txt", "rt", stdin); int t; scanf("%d%d", &t, &n); for (int i = 0; i < n; ++i) scanf("%lld", &arr[i]); printf("%lld", findGap(t, n)); return 0; } #endif

컴파일 시 표준 에러 (stderr) 메시지

gap.cpp: In function 'll findGap(int, int)':
gap.cpp:53:19: warning: variable 'pos' set but not used [-Wunused-but-set-variable]
   ll gap = 0; int pos = 0;
                   ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...