이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "wiring.h"
#include <bits/stdc++.h>
using namespace std;
long long min_total_length(vector<int>r,vector<int>b){
vector<pair<long long,bool>>V;
for(int i:r){
V.push_back({i,0});
}
for(int i:b){
V.push_back({i,1});
}
sort(V.begin(),V.end());
long long l[2];
int N=V.size();
l[0]=l[1]=-0xE869120E869120;
vector<vector<long long>>DP(N+1,vector<long long>(1<<7,0xE869120E869120));
for(int i=0;i<10;i++){
V.push_back({0xE869120E869120,i&1});
}
DP[0][0]=0;
for(int i=0;i<N;i++){
for(int j=0;j<(1<<7);j++){
if(j&1){
DP[i+1][j/2]=min(DP[i+1][j/2],DP[i][j]);
}
else{
DP[i+1][j/2]=min(DP[i+1][j/2],DP[i][j]+V[i].first-l[!V[i].second]);
for(int k=1;k<7;k++){
if(V[i].second!=V[i+k].second){
int t=(j|(1<<k));
t/=2;
DP[i+1][t]=min(DP[i+1][t],DP[i][j]+V[i+k].first-V[i].first);
}
}
}
}
l[V[i].second]=V[i].first;
}
return DP[N][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... |