Submission #98560

#TimeUsernameProblemLanguageResultExecution timeMemory
98560someone_aaBoxes with souvenirs (IOI15_boxes)C++17
100 / 100
911 ms286380 KiB
#include <bits/stdc++.h> //#include "boxes.h" #define ll long long #define pb push_back #define mp make_pair #define P pair<ll, ll> using namespace std; const int maxn = 10000100; ll dp[maxn], n, k, l; int arr[maxn]; long long delivery(int N, int K, int L, int p[]) { for(int i=0;i<N;i++) { arr[i+1] = p[i]; } n = N; k = K; l = L; deque<P>dq1, dq2; dq1.pb(mp(0, 0)); dq2.pb(mp(2LL * (l - arr[1]), 0)); for(int i=1;i<=n;i++) { // solve for prefix of size i ll f = dq1.front().first; ll s = dq2.front().first; dp[i] = min(f + min(l, 2LL*arr[i]), s); while(dq1.size() > 0 && dq1.back().first >= dp[i]) { dq1.pop_back(); } dq1.push_back(mp(dp[i], i)); while(dq2.size() > 0 && dq2.back().first >= dp[i] + 2LL * (l - arr[i+1])) { dq2.pop_back(); } dq2.push_back(mp(dp[i] + 2LL*(l-arr[i+1]), i)); // check firsts if(dq1.front().second == i-k) dq1.pop_front(); if(dq2.front().second == i-k) dq2.pop_front(); } return dp[n]; }
#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...