Submission #54608

#TimeUsernameProblemLanguageResultExecution timeMemory
54608aomeBoxes with souvenirs (IOI15_boxes)C++17
10 / 100
2 ms380 KiB
#include "boxes.h"

#include <bits/stdc++.h>

using namespace std;

const int M = 10000005;
const long long INF = 1e18;

long long f[2][M], g[M];

long long delivery(int N, int K, int L, int p[]) {
	int pos = -1;
	for (int i = 0; i < N; ++i) if (p[i] * 2 <= L) pos = i;
	for (int i = 0; i <= pos; ++i) {
		if (i + 1 <= K) f[0][i] = p[i] * 2;
		else f[0][i] = f[0][i - K] + p[i] * 2;
	}
	for (int i = N - 1; i > pos; --i) {
		if (N - pos <= K) f[1][i] = (L - p[i]) * 2;
		else f[1][i] = f[1][i + K] + (L - p[i]) * 2;
	}
	for (int i = 0; i <= K; ++i) g[i] = INF;
	for (int i = pos; i >= 0; --i) {
		if (pos - i > K) break;
		g[pos - i] = f[0][i];
	}
	for (int i = 1; i <= K; ++i) g[i] = min(g[i], g[i - 1]);
	long long res = INF;
	res = min(res, g[0] + f[1][pos + 1]);
	for (int i = pos + 1; i < N; ++i) {
		if (i - pos - 1 > K) break;
		res = min(res, f[1][i] + g[K - (i - pos - 1)] + L);
	}
	return res;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...