이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include "wiring.h"
using ll = long long;
ll myabs(ll x){
if(x<0)return x*(-1);
return x;
}
typedef std::pair<ll,ll> pll;
long long bestcusto(std::vector<int> anl,ll z){
ll best=1e9;
for(auto&x:anl){
best=std::min(best,myabs(x-z));
}
return best;
}
long long min_total_length(std::vector<int> r, std::vector<int> b) {
ll ans=0;
for(auto&x:r)ans+=bestcusto(b,x);
for(auto&x:b)ans+=bestcusto(r,x);
std::priority_queue<ll,std::vector<ll>,std::greater<ll>> abrer,abreb;
std::vector<pll> vec;
for(auto&x:r)vec.push_back({x,0});
for(auto&x:b)vec.push_back({x,1});
std::sort(vec.begin(),vec.end());
for(auto&x:vec){
ll cor=x.second;
ll pos=x.first;
if(!cor){///Vermelho
ll custo = bestcusto(b,pos);
ll delta = pos-custo;
ll melhor = 1e9;
if(abreb.size()){
melhor=abreb.top();
}
if(melhor+delta<0){
ans+=melhor+delta;
abreb.pop();
}else abrer.push(-pos-custo);
}else {///Azul
ll custo = bestcusto(r,pos);
ll delta = pos-custo;
ll melhor = 1e9;
if(abrer.size()){
melhor=abrer.top();
}
if(melhor+delta<0){
ans+=melhor+delta;
abrer.pop();
}else abreb.push(-pos-custo);
}
}
return ans;
}
# | 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... |