이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "boxes.h"
#include <vector>
#include <algorithm>
#include <map>
#include <iostream>
#define INF 1'000'000'000'000'000'000
std::vector<long long> people;
long long n, l, k;
long long dist(long long curr)
{
return std::min(l - people[curr], people[curr]);
}
long long dp[1005][1005];
long long f(long long curr, long long pres)
{
if (dp[curr][pres])
return dp[curr][pres];
if (curr == n)
return dp[curr][pres] = dist(curr);
long long optionA = pres ? std::abs(people[curr] - people[curr+1]) + f(curr + 1, pres - 1) : INF;
long long optionB = dist(curr) + dist(curr + 1) + f(curr + 1, k-1);
return dp[curr][pres] = std::min(optionA, optionB);
}
long long delivery(int N, int K, int L, int p[])
{
n = N, k = K, l = L;
people.push_back(0);
for (int i = 0; i < N; ++i)
people.push_back(p[i]);
std::sort(people.begin(), people.end());
return f(0, K - 1);
}
# | 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... |