Submission #1101024

#TimeUsernameProblemLanguageResultExecution timeMemory
1101024azberjibiouShortcut (IOI16_shortcut)C++17
0 / 100
2 ms10716 KiB
#include "shortcut.h" #include <bits/stdc++.h> #define all(v) v.begin(), v.end() #define pb push_back #define lb lower_bound #define gibon ios::sync_with_stdio(false); cin.tie(0); #define fi first #define se second #define pii pair<int, int> #define pll pair<ll, ll> typedef long long ll; using namespace std; const int mxN=1000005; const int mxM=2200005; const int mxK=61; const int MOD=1e9+7; const ll INF=1e18; int N; ll A[mxN], D[mxN]; pll l[mxN]; ll r[mxN], rl[mxN], suffix_rl[mxN]; ll C; void input(){ cin >> N; for(int i=1;i<N;i++) cin >> A[i]; for(int i=0;i<N;i++) cin >> D[i]; cin >> C; } void init(int n, std::vector<int> l, std::vector<int> d, int c){ N=n; for(int i=1;i<N;i++) A[i]=l[i]; for(int i=0;i<N;i++) D[i]=d[i]; C=c; } void make_prefix(){ for(int i=1;i<N;i++) A[i]+=A[i-1]; // make l for(int i=0;i<N;i++) l[i]=pll(A[i]-D[i], i); sort(l, l+N); // make r, rl, suffix_rl vector <pll> v(N); for(int i=0;i<N;i++) v[i]=pll(A[i]+D[i], i); sort(all(v)); for(int i=0;i<N;i++) r[i]=v[i].fi, rl[i]=v[i].fi-2*D[v[i].se]; suffix_rl[N]=1e18; for(int i=N-1;i>=0;i--){ suffix_rl[i]=min(suffix_rl[i+1], rl[i]); } /* printf("A: "); for(int i=0;i<N;i++) printf("%lld ", A[i]); printf("\nl: "); for(int i=0;i<N;i++) printf("(%lld %lld) ", l[i].fi, l[i].se); printf("\nr: "); for(int i=0;i<N;i++) printf("%lld ", r[i]); printf("\nrl: "); for(int i=0;i<N;i++) printf("%lld ", rl[i]); printf("\n"); */ } bool tf(ll lim){ // c1 <= x+y <= c2, c3 <= y-x <= c4 pll pp=pll(-1e18, 1e18), pm=pll(-1e18, 1e18); int rc=0; for(int i=0;i<N;i++){ int now=l[i].se; assert(0<=now && now<N); if(r[N-1]-l[i].fi<=lim) break; while(r[rc]-l[i].fi<=lim) rc++; if(lim<C+D[now]) return false; ll delta=lim-C-D[now]; ll lval=r[N-1]-delta, rval=suffix_rl[rc]+delta; pp.fi=max(pp.fi, A[now]+lval), pp.se=min(pp.se, A[now]+rval); pm.fi=max(pm.fi, lval-A[now]), pm.se=min(pm.se, rval-A[now]); } //printf("pp=%lld %lld, pm=%lld %lld\n", pp.fi, pp.se, pm.fi, pm.se); int s=0, e=0; for(int i=0;i<N;i++){ while(s<N && (A[i]+A[s]<pp.fi || A[s]-A[i]<pm.fi)) s++; while(s-1>=0 && A[i]+A[s-1]>=pp.fi && A[s-1]-A[i]>=pm.fi) s--; while(e>0 && (A[i]+A[e]>pp.se || A[e]-A[i]>pm.se)) e--; while(e+1<N && A[i]+A[e+1]<=pp.se && A[e+1]-A[i]<=pm.se) e++; if(s!=N && e!=-1 && s<=e) return true; } return false; } ll solv(){ make_prefix(); ll s=0, e=1e16; while(s!=e){ ll mid=(s+e)/2; if(tf(mid)) e=mid; else s=mid+1; } return e; } long long find_shortcut(int n, std::vector<int> l, std::vector<int> d, int c) { init(n, l, d, c); return solv(); } /* int main(){ input(); printf("%lld", solv()); } */
#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...