이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll min_total_length(vector<int> r, vector<int> b)
{
if(r.size() > b.size()) swap(r, b);
int n = r.size(), m = b.size();
vector<pair<int,int> > vec;
for(int i = 0; i < n; i ++)
vec.push_back({r[i], 0});
for(int i = 0; i < m; i ++)
vec.push_back({b[i], 1});
sort(vec.begin(), vec.end());
long long ans = 0;
vector<pair<int,int> > st;
for(int i = 0; i < vec.size(); i ++)
{
if(st.empty() || st.back().second == vec[i].second)
st.push_back(vec[i]);
else
{
ans += vec[i].first - st.back().first;
st.pop_back();
}
}
for(auto [x, y] : st)
{
int i = upper_bound(r.begin(), r.end(), x) - r.begin();
int c = 2e9;
if(i < r.size())
c = min(r[i] - x, c);
i--;
if(i >= 0)
c = min(x - r[i], c);
ans += c;
// cerr << c << endl;
}
return ans;
}
/*
int main()
{
int n, m;
cin >> n >> m;
vector<int> a(n), b(m);
for(int i = 0; i < n; i ++) cin >> a[i];
for(int i = 0; i < m ; i ++) cin >> b[i];
cout << min_total_length(a, b);
return 0;
}
// */
컴파일 시 표준 에러 (stderr) 메시지
wiring.cpp: In function 'll min_total_length(std::vector<int>, std::vector<int>)':
wiring.cpp:23:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
23 | for(int i = 0; i < vec.size(); i ++)
| ~~^~~~~~~~~~~~
wiring.cpp:38:12: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
38 | if(i < r.size())
| ~~^~~~~~~~~~
# | 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... |