Submission #139033

#TimeUsernameProblemLanguageResultExecution timeMemory
139033SirCenessShortcut (IOI16_shortcut)C++14
0 / 100
2 ms396 KiB
#include "shortcut.h" #include <bits/stdc++.h> #define pb push_back #define mp make_pair #define inside sl<=l&&r<=sr #define outside r<sl||sr<l #define orta ((l+r)>>1) #define INF 1000000009 #define mod 1000000007 #define ppair(x); cerr << "(" << x.first << ", " << x.second << ")\n"; #define bas(x) #x << ": " << x << " " #define prarr(x, n); cerr << #x << ": "; for(int qsd = 0; qsd < n; qsd++) cerr << x[qsd] << " "; cerr << "\n"; #define prarrv(x); cerr << #x << ": "; for(int qsd = 0; qsd < (int)x.size(); qsd++) cerr << x[qsd] << " "; cerr << "\n"; using namespace std; typedef long long ll; vector<ll> lmax; vector<ll> rmax; int c; int n; vector<int> l, d; vector<ll> pre; ll dist(int ll, int rr){ return abs(pre[rr] - pre[ll]); } ll getl(int i){ return max(lmax[i], (ll)d[i]); } ll getr(int i){ return max(rmax[i], (ll)d[i]); } int check(ll val){ int pl = 0; int pr = n-1; int islem = 1; while (islem){ islem = 0; for (int i = 0; i < n; i++){ ll rig = d[i] + dist(i, pl) + c + getr(pr); rig = min(rig, d[i] + rmax[i]); while (pl < pr && rig > val){ pl++; rig = d[i] + dist(i, pl) + c + getr(pr); rig = min(rig, d[i] + rmax[i]); islem = 1; } ll lef = d[i] + dist(i, pr) + c + getl(pl); lef = min(lef, d[i] + lmax[i]); while (pl < pr && lef > val){ pr--; lef = d[i] + dist(i, pr) + c + getl(pl); lef = min(lef, d[i] + lmax[i]); islem = 1; } if (pl == pr) return 0; } } return 1; } ll find_shortcut(int N, vector<int> L, vector<int> D, int C){ l = L; d = D; n = N; c = C; lmax.pb(0); for (int i = 1; i < n; i++){ lmax.pb(max(lmax[i-1] + l[i-1], (ll)l[i-1] + d[i-1])); } rmax.resize(n); rmax[n-1] = 0; for (int i = n-2; i >= 0; i--){ rmax[i] = max(rmax[i+1] + l[i], (ll)l[i] + d[i+1]); } pre.pb(0); for (int i = 1; i < n; i++){ pre.pb(pre[i-1] + l[i-1]); } ll bas = 0; ll son = 1e15+1; while (bas < son){ int m = (bas+son)>>1; if (check(m)) son = m; else bas = m+1; } return bas; }
#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...