Submission #30758

#TimeUsernameProblemLanguageResultExecution timeMemory
30758aybalaGap (APIO16_gap)C++11
30 / 100
2000 ms5144 KiB
#include "gap.h" #include<bits/stdc++.h> #define fori(a,b,c) for(int a=b; a<c; a++) #define ford(a,b,c) for(int a=b; a>=c; a--) #define ll long long #define pb push_back #define mp make_pair #define pii pair<int,int> #define fi first #define se second using namespace std; long long findGap(int T, int N) { if(T==1){ ll lmn=-1, lmx=1000000000000000001; ll ans=0; fori(i,0,(N+1)/2){ ll mn,mx; MinMax(lmn+1,lmx-1,&mn,&mx); if(i!=0){ ans=max(ans,mn-lmn); ans=max(ans,lmx-mx); } if(i==(N+1)/2-1){ ans=max(ans,mx-mn); } lmn=mn; lmx=mx; //cout << ans << " " << i << " " << endl; } return ans; } ll lmn=-1, lmx=1000000000000000001; ll ans=0; ll mn,mx; MinMax(lmn+1,lmx-1,&mn,&mx); lmn=mn; lmx=mx; if(N==2) return mx-mn; while(1){ if(lmn+ans>=lmx) break; while(1){ if(lmn+ans>=lmx) break; MinMax(lmn+1,lmn+ans+1,&mn,&mx); if(mn!=-1){ ans=max(ans,mn-lmn); lmn=mn; } else break; } int canans=ans+1; while(1){ if(lmn+ans>=lmx){ break; } MinMax(lmn+canans,lmn+2*canans,&mn,&mx); if(mn==-1){ canans*=2; canans+=1; } else{ ans=max(ans,mn-lmn); lmn=mx; break; } } } return ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...