Submission #389586

#TimeUsernameProblemLanguageResultExecution timeMemory
389586WLZBoxes with souvenirs (IOI15_boxes)C++14
100 / 100
607 ms307404 KiB
#include "boxes.h" #include <bits/stdc++.h> using namespace std; long long delivery(int N, int K, int L, int p[]) { vector<long long> left(N), right(N), pre(N); for (int i = 0; i < N; i++) { if (i < K) left[i] = p[i]; else left[i] = left[i - K] + p[i]; } for (int i = N - 1; i >= 0; i--) { if (i >= N - K) right[i] = L - p[i]; else right[i] = right[i + K] + L - p[i]; } long long ans = min(2 * left[N - 1], 2 * right[0]); for (int i = 1; i < N; i++) ans = min(ans, 2 * left[i - 1] + 2 * right[i]); if (K < N) { ans = min(ans, L + 2 * right[K]); ans = min(ans, L + 2 * left[N - K - 1]); for (int i = 1; i + K < N; i++) ans = min(ans, 2 * left[i - 1] + L + 2 * right[i + K]); } else { ans = min(ans, (long long) 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...