이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "boxes.h"
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e18;
template<class T>void minimize(T& a, T b){
if(a > b){
a = b;
}
}
ll delivery(int n, int k, int L, int p[]){
if(k == 1){
ll ans = 0;
for(int i = 0; i < n; i++){
ans += min(p[i], L - p[i]) << 1;
}
return ans;
}
if(k == n){
ll ans = min(L, min(p[n - 1], L - p[0]) << 1);
for(int i = 0; i + 1 < n; i++){
minimize(ans, ll(p[i] + L - p[i + 1]) << 1LL);
}
return ans;
}
if(n <= 10){
vector<int>d(1, 0);
for(int i = 0; i < n; i++){
if(p[i] != d.back()){
d.emplace_back(p[i]);
}
}
vector<vector<vector<ll>>>dp(d.size(), vector<vector<ll>>(k + 1, vector<ll>(1 << n, INF)));
dp[0][k][(1 << n) - 1] = 0;
for(int mask = (1 << n) - 1; mask > -1; mask--){
for(int i = 1; i < d.size(); i++){
for(int j = 0; j <= k; j++){
minimize(dp[0][k][mask], dp[i][j][mask] + min(d[i], L - d[i]));
}
}
for(int i = 0; i < d.size(); i++){
for(int j = 0; j < d.size(); j++){
for(int t = 0; t <= k; t++){
minimize(dp[j][t][mask], dp[i][t][mask] + min(abs(d[i] - d[j]), L - abs(d[i] - d[j])));
}
}
}
for(int i = 0; i < d.size(); i++){
for(int j = 1; j <= k; j++){
for(int t = 0; t < n; t++){
if(1 << t & mask){
minimize(dp[lower_bound(d.begin(), d.end(), p[t]) - d.begin()][j - 1][mask ^ (1 << t)], dp[i][j][mask] + min(abs(d[i] - p[t]), L - abs(d[i] - p[t])));
}
}
}
}
}
assert(n != 1);
return dp[0][k][0];
}
}
컴파일 시 표준 에러 (stderr) 메시지
boxes.cpp: In function 'll delivery(int, int, int, int*)':
boxes.cpp:36:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
36 | for(int i = 1; i < d.size(); i++){
| ~~^~~~~~~~~~
boxes.cpp:41:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
41 | for(int i = 0; i < d.size(); i++){
| ~~^~~~~~~~~~
boxes.cpp:42:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
42 | for(int j = 0; j < d.size(); j++){
| ~~^~~~~~~~~~
boxes.cpp:48:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
48 | for(int i = 0; i < d.size(); i++){
| ~~^~~~~~~~~~
boxes.cpp:61:1: warning: control reaches end of non-void function [-Wreturn-type]
61 | }
| ^
# | 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... |