Submission #101962

#TimeUsernameProblemLanguageResultExecution timeMemory
101962tim25871014Wiring (IOI17_wiring)C++17
20 / 100
44 ms3856 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*m <= 100000000){ 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...