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"
const int MX=1e5+5;
long long min_total_length(vector<int> r, vector<int> b){
vector<int>v(2e5+5,0);
for(int i=0;i<(int)r.size();i++){
v[r[i]]=1;
}
int say=0,n=(int)r.size() + (int)b.size();
vector<int>tt;
for(int i=0;i<=n;i++){
if(i==0 || v[i]==v[i-1]){
say++;
}
else{
tt.push_back(say);
say=1;
}
}
tt.push_back(say);
long long res=0;
int j=1,i=0;
while(i<j && j<n){
if(tt[i]==0){
continue;
}
int tmp=min(tt[i],tt[j]);
res+=(tmp*tmp);
tt[i]-=tmp;
tt[j]-=tmp;
if(tt[i]==0){
i++;
}
if(tt[j]==0){
j++;
}
}
return res;
}
# | 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... |