Submission #1220619

#TimeUsernameProblemLanguageResultExecution timeMemory
1220619jer033Gap (APIO16_gap)C++20
100 / 100
48 ms3364 KiB
#include <bits/stdc++.h> #include "gap.h" using namespace std; using ll = long long; ll findGap1(int N) { ll lo = 0; ll hi = 1000000000000000000; int calls = (N+1)/2; vector<ll> arr; for (int x=0; x<calls; x++) { ll ai, ani; MinMax(lo, hi, &ai, &ani); if (ai!=-1) { arr.push_back(ai); arr.push_back(ani); lo = ai+1; hi = ani-1; } } sort(arr.begin(), arr.end()); ll max_diff = 0; for (int i=0; i<(arr.size()-1); i++) { max_diff = max(max_diff, arr[i+1]-arr[i]); //cout << arr[i+1]-arr[i] << '\n'; } return max_diff; } ll findGap2(ll N) { ll lo, hi; MinMax(0, 1000000000000000000, &lo, &hi); ll partition = (hi-lo+1)/(N); ll rem = (hi-lo+1)%(N); ll curr = lo; vector<ll> arr = {lo,hi}; for (ll i=0; i<(N); i++) { ll diff = partition; if (i < rem) diff++; ll a, b; a=-1;b=-1; if (curr==lo) { if (diff >= 2) MinMax(curr+1, curr+diff-1ll, &a, &b); } else if ((curr+diff-1ll) == hi) { if (diff >= 2) MinMax(curr, curr+diff-2ll, &a, &b); } else { MinMax(curr, curr+diff-1ll, &a, &b); } arr.push_back(a); arr.push_back(b); curr = curr+diff; } ll max_diff = 0; sort(arr.begin(), arr.end()); for (int i=0; i<(arr.size()-1); i++) if (arr[i]!=-1ll) { max_diff = max(max_diff, arr[i+1]-arr[i]); //cout << i << ' ' << arr[i+1] << ' ' << arr[i] << '\n'; } return max_diff; } ll findGap(int T, int N) { if (T==1) return findGap1(N); return findGap2(N); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...