Submission #1320746

#TimeUsernameProblemLanguageResultExecution timeMemory
1320746crispxxGap (APIO16_gap)C++20
100 / 100
46 ms2340 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; vector<ll> a; while(l <= r && (int)a.size() < n) { ll mn, mx; MinMax(l, r, &mn, &mx); if(mn == -1) break; a.push_back(mn); a.push_back(mx); l = mn + 1, r = mx - 1; } sort(a.begin(), a.end()); ll ans = 0; 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...