이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#ifndef LOCAL
#include "boxes.h"
#endif
#include <vector>
#include <algorithm>
#include <iostream>
template <class T>
using Vec = std::vector<T>;
constexpr long long INF = 1000000000000000000;
long long delivery(int N, int K, int Len, int P[]) {
Vec<int> left, right;
left.reserve(N);
right.reserve(N);
for (int i = 0; i < N; ++i) {
const auto l = P[i];
const auto r = Len - P[i];
if (l <= r) {
left.push_back(l);
}
else {
right.push_back(r);
}
}
std::reverse(right.begin(), right.end());
const int L = (int) left.size();
const int R = (int) right.size();
Vec<long long> dp_l(L + 1), dp_r(R + 1);
for (int i = 1; i <= L; ++i) {
dp_l[i] = dp_l[(i >= K ? i - K : 0)] + 2 * left[i - 1];
}
for (int i = 1; i <= R; ++i) {
dp_r[i] = dp_r[(i >= K ? i - K : 0)] + 2 * right[i - 1];
}
Vec<long long> dp(N + 1, INF);
for (int i = 0; i <= L; ++i) {
for (int j = 0; j <= R; ++j) {
dp[i + j] = std::min(dp[i + j], dp_l[i] + dp_r[j]);
}
}
long long ret = INF;
for (int i = 0; i <= N; ++i) {
const auto first = (long long) Len * ((N - i + K - 1) / K);
const auto second = dp[i];
ret = std::min(ret, first + second);
}
return ret;
}
#ifdef LOCAL
int main() {
int N, K, L;
std::cin >> N >> K >> L;
int P[100] = {};
for (int i = 0; i < N; ++i) {
std::cin >> P[i];
}
std::cout << delivery(N, K, L, P) << '\n';
return 0;
}
#endif
# | 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... |