# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
63755 | 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;
}
else if (here != n)
{
p[i] = l - p[i];
}
}
if (here == 0)
{
int cur = k;
long long int sum = p[n - 1];
for (int i = n - 2; i >= 0; --i)
{
if (cur == 0)
{
sum += p[i + 1] * 2LL + p[i] - p[i + 1];
cur = k - 1;
}
else
{
sum += p[i] - p[i + 1] * 1LL;
--cur;
}
}
return sum + p[0] * 1LL;
}
else if (here == n)
{
int cur = 0;
long long int sum = p[0];
for (int i = 1; i < n; ++i)
{
if (cur == 0)
{
sum += p[i - 1] * 2LL + p[i] - p[i - 1];
cur = k - 1;
}
else
{
sum += p[i] - p[i - 1] * 1LL;
--cur;
}
}
return sum + p[n - 1] * 1LL;
}
long long int sumleft = p[0], leftleft = -1;
int cur = k - 1;
for (int i = 1; i < here; ++i)
{
if (cur == 0)
{
sumleft += p[i - 1] * 2LL + p[i] - p[i - 1];
cur = k - 1;
}
else
{
sumleft += p[i] - p[i - 1] * 1LL;
--cur;
}
}
sumleft += p[here - 1];
leftleft = cur;
long long int sumright = p[n - 1], leftright = -1;
cur = k - 1;
for (int i = n - 2; i >= here; --i)
{
if (cur == 0)
{
sumright += p[i + 1] * 2LL + p[i] - p[i + 1];
cur = k - 1;
}
else
{
sumright += p[i] - p[i + 1] * 1LL;
--cur;
}
}
sumright += p[here];
leftright = cur;
return sumleft + sumright;
}
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... |