제출 #1051987

#제출 시각아이디문제언어결과실행 시간메모리
1051987Unforgettablepl전선 연결 (IOI17_wiring)C++17
7 / 100
118 ms262144 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...