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;
typedef long long ll;
#define MAXN 100005
#define MAXM 100005
#define INFL (ll)2e18
#define INF (int)2e9
ll dp[MAXN+MAXM];
vector<pair<ll,int>> points;//0=red,1=blue
ll min_total_length(vector<int> r, vector<int> b) {
//merge sort
/* for(int i=0,j=0;i<r.size()||j<b.size();){
if(i>=r.size()||(j<b.size()&&r[i]>b[j])){
points.push_back({b[j],1});
j++;
}else{
points.push_back({r[i],0});
i++;
}
}
int pos=1;
while(points[pos].second==points[pos-1].second) pos++;*/
if(b[0]<r[0]) swap(b,r);
r.push_back(INF);
b.push_back(INF);
int pos_r=1,pos_b=1;
ll sumr=0,sumb=0;
while(r[pos_r]<b[0]){
sumr+=pos_r*((ll)r[pos_r]-r[pos_r-1]);
pos_r++;
}
ll dist=b[0]-r[pos_r-1];
while(b[pos_b]<r[pos_r]){
sumb+=b[pos_b]-b[0];
pos_b++;
}
return sumr+sumb+max(r.size()-1,b.size()-1)*dist;
}
# | 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... |