Submission #728610

#TimeUsernameProblemLanguageResultExecution timeMemory
728610aryan12Boxes with souvenirs (IOI15_boxes)C++17
100 / 100
641 ms367432 KiB
#include "boxes.h" #include <bits/stdc++.h> using namespace std; const long long INF = 1e18; long long delivery(int N, int K, int L, int p[]) { long long a[N + 1]; for(int i = 1; i <= N; i++) { a[i] = p[i - 1]; } long long pref[N + 2], suf[N + 2]; pref[0] = 0; for(int i = 1; i <= N; i++) { pref[i] = (i <= K) ? a[i] * 2LL : a[i] * 2LL + pref[i - K]; } suf[N + 1] = 0; for(int i = N; i > 0; i--) { suf[i] = (i + K - 1 > N) ? (L - a[i]) * 2LL : (L - a[i]) * 2LL + suf[i + K]; } long long ans = suf[1]; for(int i = 0; i <= N; i++) { ans = min(ans, pref[i] + suf[i + 1]); if(i + K <= N) { ans = min(ans, pref[i] + L + suf[i + K + 1]); } else { ans = min(ans, pref[i] + L); } } return ans; }
#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...