Submission #1320754

#TimeUsernameProblemLanguageResultExecution timeMemory
1320754crispxxGap (APIO16_gap)C++20
100 / 100
47 ms1204 KiB
#include "gap.h" #include <bits/stdc++.h> using namespace std; using ll = long long; bool chmax(ll &a, const ll &b) { return a < b ? a = b, true : false; } long long findGap(int T, int n) { if(T == 1) { ll l = 0, r = 1e18; ll ans = 0, cnt = 0; bool flag = true; while(l <= r && cnt < n) { ll mn, mx; MinMax(l, r, &mn, &mx); if(mn == -1) { chmax(ans, (r + 1) - (l - 1)); break; } if(!flag) { chmax(ans, mn - (l - 1)); chmax(ans, (r + 1) - mx); } cnt += 2; flag = false; l = mn + 1, r = mx - 1; } if(l <= r) { chmax(ans, (r + 1) - (l - 1)); } // for(int i = 1; i < (int)a.size(); i++) { // ans = max(ans, a[i] - a[i - 1]); // } return ans; } else { ll L, R; MinMax(0, 1e18, &L, &R); ll lmn = L, lmx = L; ll B = (R-L+n-2) / (n-1); L ++ ; ll ans = B; for(int i = 0; 1; i++) { ll cl = i * B + L, cr = min(L + (i + 1) * B - 1, R); if(cl>R)break; ll mn, mx; MinMax(cl, cr, &mn, &mx); // cout << cl << ' ' << cr << ' ' << mn << ' ' << mx << '\n'; if(lmn != -1 && mn != -1) { chmax(ans, mn - lmx); } if(mn != -1) { lmn = mn, lmx = mx; } } return ans; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...