Submission #59035

#TimeUsernameProblemLanguageResultExecution timeMemory
59035CrownShortcut (IOI16_shortcut)C++14
31 / 100
2033 ms1640 KiB
#include "shortcut.h" #include <bits/stdc++.h> using namespace std; #define X first #define Y second #define pb push_back typedef pair<int, int> ii; typedef long long ll; const int maxn = 505; vector<ll> qs; vector<int> l, d; int c, n; long long find_shortcut(int _n, vector<int> _l, vector<int> _d, int _c) { l = _l; d = _d; c = _c; n = _n; ll ret = 1e18; for(int a = 0; a< n; a++) { for(int b = a+1; b< n; b++) { //printf("oh %d and %d is\n", a, b); ll res = -1e18; vector<ll> L, D; for(int i = a; i< b; i++) L.pb(l[i]); L.pb(c); int sz = b-a+1; D.assign(sz, 0); for(int i = a+1; i< b; i++) { D[i-a] = d[i]; } ll run = 0; ll best_run = 0; for(int i = 0; i<= a; i++) { res = max(res, best_run + run + d[i]); best_run = max(best_run, d[i]-run); run += l[i]; } best_run = 0; run = 0; for(int i = b; i< n; i++) { res = max(res, best_run+run+d[i]); best_run = max(best_run, d[i]-run); if(i+1< n) run += l[i]; } //printf("not in cycle %lld\n", res); run = 0; for(int i = a; i>= 0; i--) { D[0] = max(D[0], run+d[i]); if(i) run += l[i-1]; } run = 0; for(int i = b; i< n; i++) { D.back() = max(D.back(), run+d[i]); if(i< n-1) run += l[i]; } for(int i = 0; i< sz; i++) D.pb(D[i]); vector< ll > Q; for(int i = 0; i< sz; i++) { if(Q.empty()) Q.pb(L[i]); else Q.pb(Q.back()+L[i]); } ll tot = Q.back(); //printf("tot = %lld\n", tot); for(int i = 0; i+1< sz; i++) { Q.pb(Q.back()+L[i]); } //for(auto x : D) printf("%lld ", x); //printf("\n"); int lim = 0; deque< pair<long long, int> > dq; for(int i = 0; i< sz+sz; i++) { while(i && 2LL*(Q[i-1]-(lim?Q[lim-1]:0))> tot) lim++; //printf("i = %d, lim = %d\n", i, lim); while(!dq.empty() && dq.front().Y< lim) dq.pop_front(); if(!dq.empty()) { res = max(res, D[i]+Q[i-1]+dq.front().X); } while(!dq.empty() && dq.back().X< (D[i]-(i?Q[i-1]:0))) dq.pop_back(); dq.push_back(make_pair(D[i]-(i?Q[i-1]:0), i)); } //printf("res is %lld\n", res); ret = min(ret, res); } } return ret; }
#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...