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;
vector<long long> get_cost_vector(int N, int K, int L, int p[]) {
vector<long long> cost(N);
for(int i = 0, cnt = K; i < N; i++, cnt--) {
if(cnt == 0) {
cnt = K, cost[i] += 2*p[i-1];
}
cost[i] += p[i]-(i?p[i-1]:0);
if(i) cost[i] += cost[i-1];
}
return cost;
}
long long delivery(int N, int K, int L, int p[]) {
vector<long long> cost_l = get_cost_vector(N, K, L, p);
reverse(p, p+N);
for(int i = 0; i < N; i++) {
p[i] = (p[i] != 0 ? L-p[i] : p[i]);
}
vector<long long> cost_r = get_cost_vector(N, K, L, p);
long long ans = min(cost_l[N-1]+p[0], cost_r[N-1]+p[N-1]);
ans = min(ans, min(cost_l[N-1]+(L-p[0]), cost_r[N-1]+(L-p[N-1])));
reverse(cost_r.begin(), cost_r.end());
reverse(p, p+N);
for(int i = 1; i < N; i++) {
ans = min(ans, cost_l[i-1]+min(p[i-1], L-p[i-1])+cost_r[i]+min(p[i], L-p[i]));
}
return ans;
}
Compilation message (stderr)
boxes.cpp: In function 'std::vector<long long int> get_cost_vector(int, int, int, int*)':
boxes.cpp:6:53: warning: unused parameter 'L' [-Wunused-parameter]
6 | vector<long long> get_cost_vector(int N, int K, int L, int p[]) {
| ~~~~^
# | 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... |