# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
801751 | _martynas | Boxes with souvenirs (IOI15_boxes) | C++11 | 1 ms | 308 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 "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[]) {
int zeroes = count(p, p+N, 0);
N -= zeroes;
for(int i = 0; i < N; i++) p[i] = p[i+zeroes];
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 = 0; i < N; i++) {
p[i] = (p[i] != 0 ? L-p[i] : p[i]);
}
// for(int i = 0; i < N; i++) {
// printf("%d: %lld %lld\n", i, cost_l[i], cost_r[i]);
// }
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)
# | 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... |