Submission #1104430

#TimeUsernameProblemLanguageResultExecution timeMemory
1104430alexander707070Shortcut (IOI16_shortcut)C++14
71 / 100
2061 ms2128 KiB
#include<bits/stdc++.h> #define MAXN 100007 using namespace std; struct rect{ long long minx,maxx; long long miny,maxy; inline friend rect operator + (rect fr,rect sc){ return {max(fr.minx,sc.minx),min(fr.maxx,sc.maxx),max(fr.miny,sc.miny),min(fr.maxy,sc.maxy)}; } }; const long long inf=1e15; int n,len[MAXN],d[MAXN],c; long long pos[MAXN]; bool ok(long long fix){ rect s={-inf,inf,-inf,inf},curr; for(int i=1;i<=n;i++){ for(int f=i+1;f<=n;f++){ if(pos[f]-pos[i]+d[i]+d[f]<=fix)continue; long long w=fix-d[i]-d[f]-c; if(w<0)return false; curr={pos[f]-pos[i]-w,pos[f]-pos[i]+w,pos[i]+pos[f]-w,pos[i]+pos[f]+w}; s=s+curr; } } for(int i=1;i<=n;i++){ for(int f=i+1;f<=n;f++){ if(pos[f]-pos[i]>=s.minx and pos[f]-pos[i]<=s.maxx and pos[f]+pos[i]>=s.miny and pos[f]+pos[i]<=s.maxy)return true; } } return false; } long long find_shortcut(int N,vector<int> L,vector<int> D, int C){ n=N; c=C; for(int i=1;i<=n-1;i++){ len[i]=L[i-1]; } for(int i=2;i<=n;i++){ pos[i]=pos[i-1]+len[i-1]; } for(int i=1;i<=n;i++){ d[i]=D[i-1]; } long long l=0,r=inf,tt; while(l+1<r){ tt=(l+r)/2; if(ok(tt)){ r=tt; }else{ l=tt; } } return r; } /*int main(){ //cout<<find_shortcut(9, {10, 10, 10, 10, 10, 10, 10, 10},{20, 0, 30, 0, 0, 40, 0, 40, 0}, 30)<<"\n"; //cout<<find_shortcut(4, {2, 2, 2},{1, 10, 10, 1}, 1)<<"\n"; cout<<find_shortcut(3, {1, 1},{1, 1, 1}, 3)<<"\n"; return 0; }*/
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...