# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
70591 | Kmcode | Wiring (IOI17_wiring) | C++14 | 55 ms | 5700 KiB |
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>
using namespace std;
#include "wiring.h"
long long int dp[202];
vector<pair<int,int> > v;
long long min_total_length(std::vector<int> r, std::vector<int> b) {
v.clear();
for(int i=0;i<r.size();i++){
v.push_back(make_pair(r[i],0)); //red
}
for(int i=0;i<b.size();i++){
v.push_back(make_pair(b[i],1)); //blue
}
sort(v.begin(),v.end());
vector<int> stk[2];
vector<int> al[2];
long long int dist=0;
for(int i=0;i<v.size();i++){
int ty=v[i].second;
int op=(ty^1);
if(stk[op].size()){
dist+=v[i].first-stk[op].back();
stk[op].pop_back();
}
else{
stk[ty].push_back(v[i].first);
}
al[ty].push_back(v[i].first);
}
for(int i=0;i<2;i++){
for(int j=0;j<stk[i].size();j++){
long long int el=stk[i][j];
int id=lower_bound(al[i^1].begin(),al[i^1].end(),el)-al[i^1].begin();
long long int f=LLONG_MAX;
if(al[i^1].size()!=id){
f=min(f,al[i^1][id]-el);
}
if(id){
f=min(f,el-al[i^1][id-1]);
}
dist+=f;
}
}
return dist;
}
Compilation message (stderr)
# | 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... |