이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "wiring.h"
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define F first
#define S second
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<vii> viii;
int min_total_length(vector<signed> r, vector<signed> b)
{
int res = 0;
int n = r.size() + b.size();
vector<pair<int, int>> a;
for (int i = 0; i < r.size(); i++)
a.push_back({ r[i], 0 });
for (int i = 0; i < b.size(); i++)
a.push_back({ b[i], 1 });
sort(a.begin(), a.end());
viii dp(n + 1, vii(r.size() + 2, vi(b.size() + 2, 1e18)));
dp[0][0][0] = 0;
int lst = 0;
int lstr, lstb;
lstr = lstb = -1e18;
for (int i = 0; i < n; i++) {
int d = a[i].F - lst;
if (a[i].S == 0)
lstr = a[i].F;
else
lstb = a[i].F;
//cout << a[i].F << ' ' << a[i].S << ' ' << d << endl;
for (int j = 0; j <= r.size(); j++) {
for (int k = 0; k <= b.size(); k++) {
if (a[i].S == 0) {
dp[i + 1][j][k] = min(dp[i][j][k] + (d * (j + k)) + (a[i].F - lstb), min(dp[i][j][k + 1] + (d * (j + k + 1)), (j > 0 ? dp[i][j - 1][k] + (d * (j + k - 1)) : (int)1e18)));
} else {
dp[i + 1][j][k] = min(dp[i][j][k] + (d * (j + k)) + (a[i].F - lstr), min(dp[i][j + 1][k] + (d * (j + k + 1)), (k > 0 ? dp[i][j][k - 1] + (d * (j + k - 1)) : (int)1e18)));
}
//cout << dp[i + 1][j][k] << ' ';
}
//cout << endl;
}
//cout << endl
// << endl;
lst = a[i].F;
}
return dp[n][0][0];
}
컴파일 시 표준 에러 (stderr) 메시지
wiring.cpp: In function 'long long int min_total_length(std::vector<int>, std::vector<int>)':
wiring.cpp:20:23: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
20 | for (int i = 0; i < r.size(); i++)
| ~~^~~~~~~~~~
wiring.cpp:22:23: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
22 | for (int i = 0; i < b.size(); i++)
| ~~^~~~~~~~~~
wiring.cpp:37:27: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
37 | for (int j = 0; j <= r.size(); j++) {
| ~~^~~~~~~~~~~
wiring.cpp:38:31: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
38 | for (int k = 0; k <= b.size(); k++) {
| ~~^~~~~~~~~~~
wiring.cpp:17:9: warning: unused variable 'res' [-Wunused-variable]
17 | int res = 0;
| ^~~
# | 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... |