# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1086283 | RiverFlow | Boxes with souvenirs (IOI15_boxes) | C++14 | 1 ms | 348 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;
const int N = (int)1e7 + 2;
int n, k;
long long l;
long long modk[N];
long long f(int x) {
return l * ( (x / k) + (x % k != 0) );
}
long long suf[N], pre[N];
long long delivery(int N, int K, int L, int p[]) {
n = N, k = K, l = L;
long long ans = (long long)1e17;
ans = min(ans, f(n) );
for(int i = 0; i < n; ++i) {
long long c = 2LL * p[i];
if (i - k >= 0) {
c += pre[i - k];
}
pre[i] = c;
}
for(int i = n - 1; i >= 0; --i) {
long long c = 2LL * (l - p[i]);
if (i + k < n) {
c += suf[i + k];
}
suf[i] = c;
}
int mi[2] = {(n - 1) % k, -1};
modk[ (n - 1) % k ] = f(n - 1) + suf[n - 1];
auto cmp = [&](int x, int y) {
return modk[x] > modk[y] ? 1 : 0;
};
for(int i = n - 2; i >= 0; --i) {
int t = (i + 1) % k;
ans = min(ans, pre[i] - f(i + 1) + modk[t]);
for(int i = 0; i < 2; ++i) if (mi[i] != t and mi[i] != -1) {
ans = min(ans, pre[i] - f(i + 1) + modk[mi[i]] + l);
}
int x = i % k;
if (i + k < n) {
modk[x] = min(modk[x], f(i) + suf[i]);
} else {
modk[x] = f(i) + suf[i];
}
if (mi[0] == x) continue ;
if (mi[1] == x) {
if (cmp(mi[0], x))
mi[1] = x;
} else {
if (cmp(mi[0], x))
mi[1] = mi[0], mi[0] = x;
else if (mi[1] == -1 or cmp(mi[1], x))
mi[1] = x;
}
}
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... |