제출 #101961

#제출 시각아이디문제언어결과실행 시간메모리
101961tim25871014전선 연결 (IOI17_wiring)C++17
20 / 100
50 ms2176 KiB
#include "wiring.h" #include <bits/stdc++.h> using namespace std; long long min_total_length(vector<int> r, vector<int> b){ int n=r.size(),m=b.size(); int minn=min(n,m); if(n<=200 && m<=200){ int dp[210][210]; dp[0][0]=abs(r[0]-b[0]); for(int i=0;i<n;i++) for(int j=0;j<m;j++){ int minn=2147483647; if(i&&j) minn=min(minn,dp[i-1][j-1]); if(i) minn=min(minn,dp[i-1][j]); if(j) minn=min(minn,dp[i][j-1]); minn+=abs(r[i]-b[j]); if(i||j) dp[i][j]=minn; } return dp[n-1][m-1]; } long long ans=0; for(int i=0;i<minn;i++) ans+=b[m-i-1]-r[i]; for(int i=minn;i<n;i++) ans+=b[0]-r[i]; for(int i=minn;i<m;i++) ans+=b[m-i-1]-r[n-1]; return ans; }
#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...