이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "boxes.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll dp[1010][1010][2], dp2[15][15][15][2];
vector<int> a;
int N, K, L;
ll solve(int l, int r, int side) {
if(l == r - 1) {
if(!side) return min(a[l], L - a[l]);
else return min(a[r], L - a[r]);
}
ll &ret = dp[l][r][side];
if(ret != -1) return ret;
if(side == 0) {
ret = solve(l + 1, r, 0) + a[l + 1] - a[l];
ret = min(ret, solve(l, r - 1, 1) + a[l] + L - a[r - 1]);
} else {
ret = solve(l, r - 1, 1) + a[r] - a[r - 1];
ret = min(ret, solve(l + 1, r, 0) + a[l + 1] + L - a[r]);
}
return ret;
}
ll solve2(int l, int r, int rem, int side) {
if(l == r - 1) {
if(!side) return min(a[l], L - a[l]);
else return min(a[r], L - a[r]);
}
ll &ret = dp2[l][r][rem][side];
if(ret != -1) return ret;
ret = 1e18;
if(!side) {
if(rem) {
ret = solve2(l + 1, r, rem - 1, 0) + a[l + 1] - a[l];
ret = min(ret, solve2(l, r - 1, K - 1, 1) + a[l] + L - a[r - 1]);
}
ll add = min(a[l], L - a[l]);
ret = min(ret, solve2(l + 1, r, K - 1, 0) + a[l + 1] + add);
ret = min(ret, solve2(l, r - 1, K - 1, 1) + L - a[r - 1] + add);
} else {
if(rem) {
ret = solve2(l, r - 1, rem - 1, 1) + a[r] - a[r - 1];
ret = min(ret, solve2(l + 1, r, K - 1, 0) + a[l + 1] + L - a[r]);
}
ll add = min(a[r], L - a[r]);
ret = min(ret, solve2(l, r - 1, K - 1, 1) + L - a[r - 1] + add);
ret = min(ret, solve2(l + 1, r, K - 1, 0) + a[l + 1] + add);
}
return ret;
}
ll delivery(int n, int k, int l, int p[]) {
N = n, K = k, L = l;
if(K == 1 || N == 1) {
ll tot = 0;
for(int i = 0; i < N; i++)
tot += 2 * min(p[i], L - p[i]);
return tot;
}
if(N == K) {
memset(dp, -1, sizeof dp);
a.push_back(0);
for(int i = 0; i < N; i++)
a.push_back(p[i]);
a.push_back(L);
return solve(0, N + 1, 0);
}
if(N <= 15) {
memset(dp2, -1, sizeof dp2);
a.push_back(0);
for(int i = 0; i < N; i++)
a.push_back(p[i]);
a.push_back(L);
return solve2(0, N + 1, K, 0);
}
}
컴파일 시 표준 에러 (stderr) 메시지
boxes.cpp: In function 'll delivery(int, int, int, int*)':
boxes.cpp:80:1: warning: control reaches end of non-void function [-Wreturn-type]
}
^
# | 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... |