이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "wiring.h"
#include <bits/stdc++.h>
using namespace std;
#define pii pair<int, int>
#define oo 1e9
long long min_total_length(std::vector<int> r, std::vector<int> b) {
#define int long long
int n = r.size() + b.size();
vector<pii> v = {{0, 0}};
for(int a : r) v.push_back({a, 0});
for(int a : b) v.push_back({a, 1});
sort(v.begin() + 1, v.end());
vector<int> pre(n + 1, 0), prex(n + 1, 0), dp(n + 1, 0);
map<int, int> mp = {{0, 0}};
for(int i = 1; i <= n; i++){
pre[i] = pre[i - 1] + ((v[i].second)? -1 : 1);
prex[i] = prex[i - 1] + ((v[i].second)? -1 : 1) * v[i].first;
int dist = oo;
if(v[i].second){
int id = lower_bound(r.begin(), r.end(), v[i].first) - r.begin();
// cout << v[i].first << "B " << id << '\n';
if(id != r.size()) dist = min(dist, r[id] - v[i].first);
if(id - 1 != -1) dist = min(dist, v[i].first - r[id - 1]);
}
else{
int id = lower_bound(b.begin(), b.end(), v[i].first) - b.begin();
// cout << v[i].first << "R " << id << '\n';
if(id != b.size()) dist = min(dist, b[id] - v[i].first);
if(id - 1 != -1) dist = min(dist, v[i].first - b[id - 1]);
}
dp[i] = dp[i - 1] + dist;
if(mp.count(pre[i])){
int id = mp[pre[i]];
dp[i] = min(dp[id] + abs(prex[i] - prex[id]), dp[i]);
}
mp[pre[i]] = i;
}
#undef int
return dp[n];
}
컴파일 시 표준 에러 (stderr) 메시지
wiring.cpp: In function 'long long int min_total_length(std::vector<int>, std::vector<int>)':
wiring.cpp:23:19: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
23 | if(id != r.size()) dist = min(dist, r[id] - v[i].first);
| ~~~^~~~~~~~~~~
wiring.cpp:29:19: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
29 | if(id != b.size()) dist = min(dist, b[id] - v[i].first);
| ~~~^~~~~~~~~~~
# | 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... |