This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#include "wiring.h"
using namespace std;
typedef long long ll;
int get_closest(int x, vector<int> &vec){
int lb = lower_bound(vec.begin(), vec.end(), x) - vec.begin();
int res = 1e9 + 10;
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) {
int n = a.size(), m = b.size();
int p = 0, q = 0;
ll ans = 0;
while (p < n and q < m){
int g1 = get_closest(a[p], b);
int 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;
}
Compilation message (stderr)
wiring.cpp: In function 'int get_closest(int, std::vector<int>&)':
wiring.cpp:11:12: warning: comparison of integer expressions of different signedness: '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... |