이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include "wiring.h"
#define ll long long
#define ff first
#define ss second
#define all(x) x.begin(),x.end()
#define pb push_back
using namespace std;
long long min_total_length(vector<int> r,vector<int> b) {
int n=r.size(),m=b.size();
ll ans=0;
vector <int> used1(n),used2(m);
for(int i=0;i<n;i++){
used1[i]=1;
ll mn=1e18,pos=-1,mn2=1e18;
for(int j=0;j<m;j++){
if(!used2[j] && abs(r[i]-b[j])<mn){
mn=abs(r[i]-b[j]);
pos=j;
}
mn2=min(mn2,(ll)abs(r[i]-b[j]));
}
if(pos==-1)ans+=mn2;
else{
used2[pos]=1;
ans+=mn;
}
}
for(int i=0;i<m;i++){
if(!used2[i]){
used2[i]=1;
ll mn=1e18,pos=-1,mn2=1e18;
for(int j=0;j<n;j++){
if(!used1[j] && abs(b[i]-r[j])<mn){
mn=abs(b[i]-r[j]);
pos=j;
}
mn2=min(mn2,(ll)abs(b[i]-r[j]));
}
if(pos==-1)ans+=mn2;
else{
used1[pos]=1;
ans+=mn;
}
}
}
return ans;
}
/*signed main(){
ios_base::sync_with_stdio();
cin.tie(0);cout.tie(0);
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);
}*/
/*
*/
# | 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... |