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;
const int nax = 1e3 + 3;
const long long INF = 1e18;
long long dp[nax];
int n, k, L;
int a[nax]; //a[0] = a[n+1] = 0
int c[nax];
int get(int i, int j) {
return min(abs(a[j]-a[i]), L-abs(a[j]-a[i]));
}
long long delivery(int N, int K, int l, int p[]) {
n = N, k = K, L = l;
for(int i=1; i<=n; ++i) {
a[i] = p[i-1];
c[i] = min(a[i], L-a[i]);
}
for(int i=1; i<=n+1; ++i) {
dp[i] = INF;
}
for(int i=0; i<=n; ++i) {
for(int j=1; j<=k; ++j) {
dp[i+j+1] = min(dp[i+j+1], dp[i] + get(i, i+j) + c[i+j] + c[i+j+1]);
}
}
return dp[n+1];
}
# | 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... |