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;
typedef long double ld;
typedef unsigned long long ull;
const int nax = 2e5 + 50;
ll dp[nax];
long long min_total_length(vector<int> r, vector<int> b) {
vector<pair<ll,int>> a;
for(int i : r)
a.push_back({i,0});
for(int i : b)
a.push_back({i,1});
sort(a.begin(),a.end());
int n = a.size();
for(int i=0;i<=n;i++)
dp[i] = 1e18;
dp[0] = 0;
int lr = -1,lb = -1;
int id1 = -1,id2 = -1;
for(int i=1;i<=n;i++){
pair<int,int> cur = a[i-1];
ll at = cur.first;
if(cur.first == 0){
if(lb != -1)
dp[i] = min(dp[i],dp[id2-1] + at - lb);
lr = at;
id1 = i;
}else{
if(lr != -1)
dp[i] = min(dp[i],dp[id1-1] + at - lr);
lb = at;
id2 = i;
}
}
return dp[n];
}
# | 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... |