이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;
const ll INF = 1000000000000000000;
//#include "wiring.h"
ll dp[200005];
ll p[200005];
int last[200005];
vector<ii> v;
ll min_total_length(vector<int> r, vector<int> b) {
int nr = r.size(), nb = b.size();
int n = nr+nb;
for (auto x: r) v.push_back({x,0});
for (auto x: b) v.push_back({x,1});
sort(v.begin(),v.end());
last[0] = -1;
dp[0] = 0;
p[0] = v[0].fi;
for (int i = 1; i < n; i++){
dp[i] = INF;
last[i] = (v[i].se == v[i-1].se) ? last[i-1] : i-1;
p[i] = p[i-1] + v[i].fi;
if (last[i] == -1) continue;
dp[i] = dp[i-1] + v[i].fi - v[last[i]].fi;
int pos = last[i]-(i-last[i]);
if (last[last[i]] <= pos){
dp[i] = min(dp[i],dp[pos]+p[i]-p[last[i]]-(p[last[i]]-p[pos]));
}
//printf("%d ",dp[i]);
}
return dp[n-1];
}
# | 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... |