제출 #299360

#제출 시각아이디문제언어결과실행 시간메모리
299360medk전선 연결 (IOI17_wiring)C++14
0 / 100
34 ms4216 KiB
#include <bits/stdc++.h> #include "wiring.h" #define ll long long #define pb push_back #define x first #define y second #define all(u) u.begin(),u.end() #define sz(u) (int)(u.size()) using namespace std; ll min_total_length(vector<int> a, vector<int> b){ int sza=sz(a), szb=sz(b); if(szb>sza) swap(a,b), swap(sza,szb); int diff=sza-szb; ll dp[sza+1][diff+1]; for(int i=0;i<=sza;i++) for(int j=0;j<=diff;j++) dp[i][j]=1e18; dp[0][0]=0; for(int i=1;i<=sza;i++){ for(int j=0;j<=diff && i-1-j>=0;j++){ if(dp[i-1][j]<1e17) if(i-1-j<szb) dp[i][j]=dp[i-1][j]+(ll)abs(a[i-1]-b[i-1-j]); ll mn=2e18; for(int k=0;k<szb;k++) mn=min(mn,(ll)abs(a[i-1]-b[k])); if(j>0) dp[i][j]=min(dp[i][j], dp[i-1][j-1]+mn); } } return dp[sza][diff]; } /* int main(){ cout<<min_total_length({1,2,3,7},{0,4,5,9,10}); }*/
#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...