Submission #374920

#TimeUsernameProblemLanguageResultExecution timeMemory
374920idk321Boxes with souvenirs (IOI15_boxes)C++11
100 / 100
559 ms231728 KiB
#include "boxes.h" #include <bits/stdc++.h> using namespace std; typedef long long ll; const ll M = 1000000000000000000LL; long long delivery(int n, int k, int l, int p[]) { vector<ll> dp1(n + 1, M); dp1[0] = 0; for (int i = 0; i < n; i++) { dp1[i + 1] = dp1[max(0, i + 1 - k)] + 2 * p[i]; } vector<ll> dp2(n + 1, M); dp2[0] = 0; for (int i = 0, j = n - 1; i < n; i++, j--) { dp2[i + 1] = dp2[max(0, i + 1 - k)] + 2 * (l - p[j]); } ll res = M; int atLeast = n / k; if (n % k != 0) atLeast++; res = min(res, (ll) atLeast * l); for (int cycle = 0; cycle <= 1; cycle++) { ll cur = l; cur *= cycle; for (int i = 0; i + (ll) cycle * k <=n; i++) { ll cur2 = cur; cur2 += dp1[i]; cur2 += dp2[n - i - cycle * k]; res = min(res, cur2); } if ((ll) cycle * k >= n) { res = min(res, cur); } } return res; } /* 5 5 100 1 3 6 53 78 */
#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...