이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include "wiring.h"
using namespace std;
typedef long long ll;
ll get_closest(ll x, vector<int> &vec){
ll lb = lower_bound(vec.begin(), vec.end(), x) - vec.begin();
ll res = 1e18;
if (lb < vec.size())
res = min(res, abs(x - vec[lb]));
lb--;
if (lb >= 0)
res = min(res, abs(x - vec[lb]));
return res;
}
ll min_total_length(vector<int> a, vector<int> b) {
ll n = a.size(), m = b.size();
ll p = 0, q = 0;
ll ans = 0;
while (p < n and q < m){
ll g1 = get_closest(a[p], b);
ll g2 = get_closest(b[q], a);
if (g1 + g2 >= abs(a[p] - b[q])){
ans += abs(a[p] - b[q]);
p++, q++;
continue;
}
if (a[p] < b[q]){
ans += g1;
p++;
}
else{
ans += g2;
q++;
}
}
while (p < n){
ans += get_closest(a[p], b);
p++;
}
while (q < m){
ans += get_closest(b[q], a);
q++;
}
return ans;
}
컴파일 시 표준 에러 (stderr) 메시지
wiring.cpp: In function 'll get_closest(ll, std::vector<int>&)':
wiring.cpp:11:12: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
11 | if (lb < vec.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... |