# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
64038 | Kubalionzzale | Boxes with souvenirs (IOI15_boxes) | C++14 | 2 ms | 376 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 <map>
#include <iostream>
#include <algorithm>
long long delivery(int n, int k, int l, int p[]) {
if (n == 1)
{
return std::min(p[0] * 2LL, (l - p[0]) * 2LL);
}
int here = n;
for (int i = 0; i < n; ++i)
{
if (p[i] > l - p[i] && here == n)
{
here = i;
}
if (i >= here)
{
p[i] = l - p[i];
}
}
if (here == 0)
{
long long int sumleft = p[0], leftleft = -1;
int cur = k - 1;
for (int i = 1; i < n; ++i)
{
if (cur == 0)
{
sumleft += p[i - 1] + p[i] * 1LL;
cur = k - 1;
}
else
{
sumleft += p[i - 1] - p[i] * 1LL;
--cur;
}
}
sumleft += p[n - 1] * 1LL;
return sumleft;
}
else if (here == n)
{
long long int sumright = p[here - 1], leftright = -1;
int cur = k - 1;
for (int i = here - 2; i >= 0; --i)
{
if (cur == 0)
{
sumright += p[i + 1] + p[i] * 1LL;
cur = k - 1;
}
else
{
sumright += p[i + 1] - p[i] * 1LL;
--cur;
}
}
sumright += p[0] * 1LL;
return sumright;
}
long long int sumleft = p[here - 1], leftleft = -1;
int cur = k - 1;
for (int i = here - 2; i >= 0; --i)
{
if (cur == 0)
{
sumleft += p[i + 1] + p[i] * 1LL;
cur = k - 1;
}
else
{
sumleft += p[i + 1] - p[i] * 1LL;
--cur;
}
}
sumleft += p[0] * 1LL;
long long int sumright = p[here], leftright = -1;
cur = k - 1;
for (int i = here + 1; i < n; ++i)
{
if (cur == 0)
{
sumright += p[i - 1] + p[i] * 1LL;
cur = k - 1;
}
else
{
sumright += p[i - 1] - p[i] * 1LL;
--cur;
}
}
sumright += p[n - 1] * 1LL;
leftright = cur;
long long int curmin = sumleft + sumright;
if (k == 1)
return curmin;
long long int curval, min = 1e17;
int where = std::max(here - k + 1, 0), start;
for (int i = std::max(here - k + 1, 0);; ++i)
{
if (i >= here)
break;
if (i + k - 1 >= n)
break;
curval = l;
if (i != 0)
{
start = i - 1;
while (1)
{
if (start == -1)
curval += p[start] * 1LL;
else
curval += p[start] * 2LL;
if (start - k >= 0)
{
curval += p[start] - p[start - k] * 1LL;
start -= k;
}
else
{
curval += p[start];
break;
}
}
}
if (i + k < n)
{
start = i + k;
while (1)
{
if (start == i + k)
curval += p[start] + 1LL;
else
curval += p[start] * 2LL;
if (start + k < n)
{
curval += p[start] - p[start + k] * 1LL;
start -= k;
}
else
{
curval += p[start];
break;
}
}
}
if (curval < min)
min = curval;
}
return std::min(curmin, min);
}
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... |