Submission #243598

#TimeUsernameProblemLanguageResultExecution timeMemory
243598uacoder123Gap (APIO16_gap)C++14
89.04 / 100
77 ms3328 KiB
#include "gap.h" #include <bits/stdc++.h> using namespace std; #define F first #define S second #define FOR(i,a,b) for (auto i = (a); i <= (b); ++i) #define NFOR(i,a,b) for(auto i = (a); i >= (b); --i) #define all(x) (x).begin(), (x).end() #define sz(x) int(x.size()) #define mp(i,a) make_pair(i,a) #define pb(a) push_back(a) #define bit(x,b) (x&(1LL<<b)) typedef long long int lli; typedef pair <lli,lli> ii; typedef pair <lli,ii> iii; typedef vector <lli> vi; long long findGap(int T, int N) { lli arr[N],l=0,g,r=1000000000000000000,l1=0,r1=N-1,ans1,ans2,m=0; if(T==1) { for(;l1<=r1;) { MinMax(l,r,&ans1,&ans2); arr[l1]=ans1; l1++; l=ans1+1; arr[r1]=ans2; r1--; r=ans2-1; } for(lli i=0;i<N-1;++i) m=max(m,arr[i+1]-arr[i]); } else { MinMax(l,r,&ans1,&ans2); l=ans1+1; r=ans2-1; g=(r-l+1)/(N-1); r1=g+l-1; vector<ii> v; v.pb(mp(ans1,ans1)); while(1) { MinMax(l,min(r,r1),&ans1,&ans2); if(r<=r1) break; l+=g; r1+=g; if(ans1!=-1) v.pb(mp(ans1,ans2)); } v.pb(mp(r+1,r+1)); for(lli i=0;i<lli(v.size())-1;++i) { m=max(m,v[i+1].F-v[i].S); } } return m; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...