# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
420387 | Azimjon | Boxes with souvenirs (IOI15_boxes) | C++17 | 1 ms | 208 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 INF = 2e9;
long long delivery(int _n, int _k, int _L, int p[]) {
long long n = _n, k = _k, L = _L;
long long x = 0;
for (x = 0; x < n; x++)
if (p[x]) break;
n -= x;
if (n == 0) return 0ll;
for (int i = 0; i < n; i++)
p[i] = p[i + x];
long long ans = 0;
long long ur = L / 2;
long long m;
for (m = 0; m < n; m++)
if (p[m] > ur) break;
long long l = m - 1;
long long r = m;
while (1) {
if (l - k + 1 >= 0) {
ans += 2 * p[l];
l -= k;
} else
break;
}
while (1) {
if (r + k - 1 < n) {
ans += 2 * (L - p[r]);
r += k;
} else
break;
}
long long o = 0;
if (l >= 0) o += 2 * p[l];
if (r < n) o += 2 * (L - p[r]);
long long q = 0;
if (l >= 0) q += l + 1;
if (r < n) q += n - r;
if (q <= k) {
o = min(o, (long long)L);
} else {
long long w = q - k;
long long v = k;
while (v--) {
if (l >= 0 && r < n && p[l] < L - p[r]) {
r++;
} else if (l >= 0 && r < n) {
l--;
} else if (l >= 0) {
l--;
} else {
r++;
}
}
long long uy = 0;
if (l >= 0) uy += 2 * p[l];
if (r < n) uy += 2 * (L - p[r]);
o = min(o, uy + L);
}
// cerr << o << endl;
return ans + o;
}
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... |