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 "boxes.h"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 1e7+10;
int n, k; ll l;
ll dp1[N], dp2[N];
long long delivery(int _n, int _k, int _l, int p[]) {
n = _n, k = _k, l = _l;
for(int i = 0; i < n; i++) {
if(i < k) dp1[i] = 2ll * p[i];
else dp1[i] = 2ll * p[i] + dp1[i - k];
}
for(int i = n - 1; i >= 0; i--) {
if(n - 1 < i + k) dp2[i] = 2ll * (p[i] == 0 ? 0 : l - p[i]);
else dp2[i] = 2ll * (p[i] == 0 ? 0 : l - p[i]) + dp2[i + k];
}
ll ans = min(dp1[n - 1], dp2[0]);
for(int i = 0; i + 1 < n; i++)
ans = min(ans, dp1[i] + dp2[i + 1]);
for(int i = 0; i + k - 1 < n; i++) {
ll one = (i ? dp1[i - 1] : 0);
ll two = (i + k < n ? dp2[i + k] : 0);
ans = min(ans, l + one + two);
}
return ans;
}
# | 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... |