Submission #297115

#TimeUsernameProblemLanguageResultExecution timeMemory
297115MercenaryShortcut (IOI16_shortcut)C++14
31 / 100
2047 ms512 KiB
#include "shortcut.h" #include<bits/stdc++.h> using namespace std; const int maxn = 1e3 + 6; typedef long long ll; ll prv[maxn]; ll suf[maxn]; ll cur[maxn]; ll pre_res[maxn]; ll suf_res[maxn]; long long find_shortcut(int n, std::vector<int> l, std::vector<int> d, int c) { vector<ll> sum(n , 0); for(int i = 1 ; i < n ; ++i){ sum[i] = sum[i - 1] + l[i - 1]; } auto dis = [&](int i , int j){ return sum[j] - sum[i]; }; for(int i = 0 ; i < n ; ++i){ if(i > 0)prv[i] = prv[i - 1] + l[i - 1]; prv[i] = max(prv[i] , (ll)d[i]); } for(int i = n - 1 ; i >= 0 ; --i){ if(i + 1 < n)suf[i] = suf[i + 1] + l[i]; suf[i] = max(suf[i] , (ll)d[i]); } ll res = 0; for(int i = 0 ; i < n ; ++i){ for(int j = i + 1 ; j < n ; ++j){ res = max(res , dis(i , j) + d[i] + d[j]); pre_res[j] = max(pre_res[j] , dis(i , j) + d[i] + d[j]); suf_res[i] = max(suf_res[i] , dis(i , j) + d[i] + d[j]); } } for(int i = 1 ; i < n ; ++i)pre_res[i] = max(pre_res[i] , pre_res[i - 1]); for(int i = n - 2 ; i >= 0 ; --i)suf_res[i] = max(suf_res[i] , suf_res[i + 1]); for(int i = 0 ; i < n ; ++i){ for(int j = i + 1 ; j < n ; ++j){ cur[j] = d[j]; if(dis(i,j) <= c)continue; ll mx = max(pre_res[i] , suf_res[j]); cur[i] = prv[i]; cur[j] = suf[j]; for(int k = i ; k <= j ; ++k){ for(int t = k + 1 ; t <= j ; ++t){ mx = max(mx , cur[k] + cur[t] + min(dis(k, t) , dis(i,j) + c - dis(k,t))); if(mx >= res)break; } } cur[j] = d[j]; res = min(res , mx); } } return res; } #ifdef LOCAL #include <cstdio> #include <cassert> #include "shortcut.h" int main() { freopen("A.INP","r",stdin); freopen("A.OUT","w",stdout); int n, c; assert(2 == scanf("%d%d", &n, &c)); std::vector<int> l(n - 1); std::vector<int> d(n); for (int i = 0; i < n - 1; i++) assert(1 == scanf("%d", &l[i])); for (int i = 0; i < n; i++) assert(1 == scanf("%d", &d[i])); long long t = find_shortcut(n, l, d, c); printf("%lld\n", t); return 0; } #endif // LOCAL
#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...