# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1086930 | codexistent | Boxes with souvenirs (IOI15_boxes) | C++14 | 0 ms | 0 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.
// Key to solution lies in the fact that you cannot have more than 1 full-circle trip.
// PROOF: Assume you have 2 full-circle trips. Then you travel 2L time and deliver >= 2K souvenirs.
// But we can easily just deliver the first k souvenirs(from clockwise direction) in 2 * x time going
// clockwise and deliver the first k souvenirs(from counter-clockwise direction) in at most 2 * (l - x)
// time going counter-clockwise, which is just as good if not better.
#include "boxes.h"
using namespace std;
#define MAXN 10000005
#define FOR(i, a, b) for(long long i = a; i <= b; i++)
#define RFOR(i, a, b) for(long long i = a; i >= b; i--)
long long dp_cw[MAXN], dp_ccw[MAXN], r = __LONG_LONG_MAX__;
long long delivery(int N, int K, int L, int p[]) {
dp_cw[0] = dp_ccw[N + 1] = 0;
FOR(i, 1, N) dp_cw[i] = dp_cw[max((long long)0, (long long)i - K)] + 2 * p[i - 1];
RFOR(i, N, 1) dp_ccw[i] = dp_ccw[min(N + 1, i + K)] + 2 * (L + 1 - p[i - 1]);
FOR(i, 0, N) r = min(r, dp_cw[i] + dp_ccw[i + 1]);
if(N >= K) FOR(i, 0, N) r = min(r, dp_cw[i] + dp_ccw[i + K + 1]);
return r;
}