이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "wiring.h"
#include "bits/stdc++.h"
using namespace std;
const int N = 200100;
long long dp[N];
const long long INF = 1e18;
long long min_total_length(std::vector<int> r, std::vector<int> b) {
vector<pair<int, int> > v;
for (auto x:r) v.push_back({x, 0});
for (auto x:b) v.push_back({x, 1});
v.push_back({-2, -3});//0
sort(v.begin(), v.end());
dp[0] = 0;
auto cost = [&](int l, int r) {
vector<int> st[2];
long long res = 0;
for (; l <= r; l++) st[v[l].second].push_back(v[l].first);
if (st[0].empty() || st[1].empty()) return INF;
for (int i = 0; i < min(st[0].size(), st[1].size()); i++) {
res += abs(st[0][i] - st[1][i]);
}
if (st[0].size() < st[1].size()) {
for (int i = st[0].size(); i < st[1].size(); i++) {
res += min(abs(st[0].back() - st[1][i]), abs(st[0].front() - st[1][i]));
}
} else {
for (int i = st[1].size(); i < st[0].size(); i++) {
res += min(abs(st[1].back() - st[0][i]), abs(st[1].front() - st[0][i]));
}
};
return res;
};
// cerr << cost(1, 3) << endl;
for (int i = 1; i < (int) v.size(); i++) {
dp[i] = INF;
for (int j = max(1, i - 14); j < i; j++) {
dp[i] = min(dp[i], dp[j - 1] + cost(j, i));
}
// cerr << dp[i] << ' ';
}
return dp[v.size() - 1];
}
컴파일 시 표준 에러 (stderr) 메시지
wiring.cpp: In lambda function:
wiring.cpp:23:27: warning: comparison of integer expressions of different signedness: 'int' and 'const long unsigned int' [-Wsign-compare]
23 | for (int i = 0; i < min(st[0].size(), st[1].size()); i++) {
| ~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
wiring.cpp:28:42: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
28 | for (int i = st[0].size(); i < st[1].size(); i++) {
| ~~^~~~~~~~~~~~~~
wiring.cpp:32:42: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
32 | for (int i = st[1].size(); i < st[0].size(); i++) {
| ~~^~~~~~~~~~~~~~
# | 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... |