이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "wiring.h"
#include <bits/stdc++.h>
using namespace std;
const int MAX_DIVERGENCE = 201;
const long long INF = 1e15;
long long min_total_length(vector<int> r, vector<int> b) {
vector<pair<int,int>> arr;
for(int&i:b)arr.emplace_back(i,0);
for(int&i:r)arr.emplace_back(i,1);
sort(arr.begin(), arr.end());
int n = arr.size();
arr.insert(arr.begin(),{false,-1});
vector DP(n+1,vector(2,vector(MAX_DIVERGENCE+1,INF)));
DP[0][0][0]=DP[0][1][0]=0;
for(int i=1;i<=n;i++) {
auto [idx,mycolour] = arr[i];
int oppocolour = mycolour^1;
DP[i][oppocolour][MAX_DIVERGENCE]=INF;
for(int j=MAX_DIVERGENCE-1;j>=0;j--) {
DP[i][oppocolour][j]=min(DP[i-1][oppocolour][j+1]+idx,DP[i][oppocolour][j+1]+idx);
}
DP[i][mycolour][0]=DP[i][oppocolour][0];
for(int j=1;j<=MAX_DIVERGENCE;j++) {
DP[i][mycolour][j]=min(DP[i-1][mycolour][j-1]-idx,DP[i][mycolour][j-1]-idx);
}
}
return DP[n][0][0];
}
# | 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... |