# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1044978 | vanea | Boxes with souvenirs (IOI15_boxes) | C++14 | 348 ms | 245256 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#include "boxes.h"
using namespace std;
using ll = long long;
using ld = long double;
const ll INF = 1e18;
ll delivery(int n, int k, int l, int p[]) {
vector<ll> dp1(n+1), dp2(n+2);
ll ans = INF;
for(int i = 1; i <= n; i++) {
int last = max(0, i-k);
ll lastP = (last ? p[last-1] : 0);
ll lastP1 = (i-1 ? p[i-2] : 0);
dp1[i] = dp1[last] + lastP*2 + p[i-1]-lastP;
}
for(int i = n; i >= 1; i--) {
int last = min(n+1, i+k);
ll lastP = (last != n+1 ? (l-p[last-1]) : 0);
ll lastP1 = (last != n+1 ? p[last-1] : l);
dp2[i] = dp2[last] + 2*lastP + lastP1-p[i-1];
}
for(int i = 0; i <= n; i++) {
ll add1 = 0, add2 = 0;
if(i) add1 = min((ll)p[i-1], (ll)l-p[i-1]);
if(i != n) add2 = min(p[i], l-p[i]);
ans = min(ans, add1+add2+dp1[i]+dp2[i+1]);
}
return ans;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |