Submission #395544

#TimeUsernameProblemLanguageResultExecution timeMemory
395544jeroenodbGap (APIO16_gap)C++14
100 / 100
77 ms3256 KiB
#include "gap.h" #include "bits/stdc++.h" using namespace std; #define all(x) begin(x),end(x) template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; } template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) { string sep; for (const T &x : v) os << sep << x, sep = " "; return os; } #define debug(a) cerr << "(" << #a << ": " << a << ")\n"; typedef long long ll; typedef vector<int> vi; typedef vector<vi> vvi; typedef pair<int,int> pi; typedef pair<ll,ll> pl; const int mxN = 1e5+1; const ll oo = 1e18; long long findGap(int T, int N) { ll amax,amin; MinMax(0,oo,&amin,&amax); if(T==1) { ll ans = 0; int left = N-2; vector<ll> a = {amin,amax}; while(left>0) { MinMax(amin+1,amax-1,&amin,&amax); left-=2; a.push_back(amin); if(amax!=amin) a.push_back(amax); } sort(all(a)); for(int i=1;i<N;++i) { ans = max(ans,a[i]-a[i-1]); } return ans; } ll ans = (amax-amin+N-2) / (N-1); // invariant: low contains a value, range [low+1, low+ans] can't contain answer ll low = amin+1; vector<pl> groups = {{amin,amin}}; while(low<amax) { ll l,r; MinMax(low,min(amax-1,low+ans),&l,&r); low += ans+1; if(l==-1) { continue; } groups.push_back({l,r}); } groups.push_back({amax,amax}); for(int i=1;i<(int)groups.size();++i) { ans = max(ans, groups[i].first - groups[i-1].second); } return ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...