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 "wiring.h"
#include<bits/stdc++.h>
using namespace std;
#define mp make_pair
#define INF 10000000
#define MOD 1000000007
#define MID ((l+r)/2)
#define HASHMOD 2305843009213693951
#define ll long long
#define ull unsigned long long
#define F first
#define S second
typedef pair<ll, ll> ii;
typedef pair<ii, int> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef map<int, int> mii;
#define EPS 1e-6
#define FOR(i,n) for(int i=0;i<((int)(n));i++)
#define FORi(i,a,b) for(int i=((int)(a));i<((int)(b));i++)
#define FOA(v, a) for(auto v : a)
map<int, int> used;
long long min_total_length(std::vector<int> r, std::vector<int> b) {
ll ans=0;
int cnt=0;
vector<int> a[2] = {r,b};
set<ii> all;
set<int> col[2];
FOA(v, a[0]) all.insert({v, 0}), col[0].insert(v);
FOA(v, a[1]) all.insert({v, 1}), col[1].insert(v);
FOA(v,all){
auto it = col[1-v.S].lower_bound(v.F);
if(it==col[1-v.S].end()){
// eneshi unused, pame se used
int d1=MOD, d2=MOD;
auto it1 = lower_bound(a[1-v.S].begin(), a[1-v.S].end(), v.F);
auto it2 = lower_bound(a[1-v.S].begin(), a[1-v.S].end(), v.F);
it2--;
if(it1!=a[1-v.S].end()) d1 =abs(v.F - *it1);
if(it1!=a[1-v.S].begin()) d2 = abs(v.F - *it2);
//cout<<v.F<<" "<<d1<<" "<<d2<<endl;
ans += min(d1, d2);
}
else{
//cout<<v.F<<" "<<*it<<endl;
ans+= abs(v.F - *it);
all.erase({*it, 1-v.S});
col[1-v.S].erase(*it);
}
}
return ans;
}
Compilation message (stderr)
wiring.cpp: In function 'long long int min_total_length(std::vector<int>, std::vector<int>)':
wiring.cpp:27:6: warning: unused variable 'cnt' [-Wunused-variable]
27 | int cnt=0;
| ^~~
# | 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... |