Submission #352377

#TimeUsernameProblemLanguageResultExecution timeMemory
352377KerimShortcut (IOI16_shortcut)C++17
100 / 100
1197 ms65172 KiB
#include "shortcut.h" #include "bits/stdc++.h" #define MAXN 1000009 #define INF 1000000007 #define mp(x,y) make_pair(x,y) #define all(v) v.begin(),v.end() #define pb(x) push_back(x) #define wr cout<<"----------------"<<endl; #define ppb() pop_back() #define tr(ii,c) for(__typeof((c).begin()) ii=(c).begin();ii!=(c).end();ii++) #define ff first #define ss second #define my_little_dodge 46 #define debug(x) cerr<< #x <<" = "<< x<<endl; using namespace std; typedef long long ll; typedef pair<ll,ll> PII; template<class T>bool umin(T& a,T b){if(a>b){a=b;return 1;}return 0;} template<class T>bool umax(T& a,T b){if(a<b){a=b;return 1;}return 0;} const ll B=1e18; vector<ll>x; vector<int>d; int n,pos; pair<int,PII>a[MAXN]; ll cost,K; PII cur[MAXN]; bool ok(ll k){K=k-cost; ll A1=-B,A2=B,B1=-B,B2=B; PII res=mp(B,-B); int p1=0,p2=0; for(int i=0;i<n;i++){ ll dif=x[i]-d[i],sum=x[i]+d[i]; while(p1<p2 and sum-cur[p1].ff>k){ umin(res.ff,cur[p1].ff); umax(res.ss,x[cur[p1].ss]+d[cur[p1].ss]); p1++; } umin(A2,dif+res.ff+K);umax(A1,sum+res.ss-K); umin(B2,dif-res.ss+K);umax(B1,sum-res.ff-K); while(p2>p1 and cur[p2-1].ff>dif)p2--; cur[p2++]=mp(dif,i); } if(A1>A2 or B1>B2)return 0; for(int j=0,p=0;j<n;j++){ ll xx=max(A1-x[j],x[j]-B2),yy=min(A2-x[j],x[j]-B1); while(p>0 and x[p-1]>=xx)p--; if(p<j and x[p]>=xx and x[p]<=yy)return 1; while(p<j and x[p]<xx)p++; } return 0; } long long find_shortcut(int N,vector<int> l,vector<int>D, int c_edge){ d=D;cost=c_edge;n=N;x.resize(n);for(int i=0;i<n;i++)x[i]=0; for(int i=0;i<n-1;i++)x[i+1]=x[i]+l[i]; ll st=1,en=ll(2e15); while(st+1<en){ ll mid=(st+en)>>1; if(ok(mid))en=mid; else st=mid; } if(ok(st))return st; return en; }
#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...