# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
693944 | T0p_ | Boxes with souvenirs (IOI15_boxes) | C++14 | 593 ms | 293628 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 = 10000000;
long long cw[N+5], ccw[N+5];
long long cost(int a, int b, int L)
{
if (a > b) swap(a, b);
return min(b-a, L-b+a);
}
long long delivery(int N, int K, int L, int p[])
{
for (int i=0 ; i<K ; i++) cw[i] = p[i];
for (int i=K ; i<N ; i++) cw[i] = cw[i-K] + p[i] + p[i-K];
for (int i=0 ; i<K ; i++) ccw[N-i-1] = L - p[N-i-1];
for (int i=K ; i<N ; i++) ccw[N-i-1] = ccw[N-i+K-1] + L - p[N-i+K-1] + L - p[N-i-1];
long long ans = 1e18;
for (int i=0 ; i<=N ; i++)
{
if (i == 0) ans = min(ans, ccw[0] + cost(p[0], 0, L));
else if (i == N) ans = min(ans, cw[N-1] + cost(p[N-1], 0, L));
else ans = min(ans, cw[i-1] + cost(p[i-1], 0, L) + ccw[i] + cost(p[i], 0, L));
}
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... |