# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
671247 | 2022-12-12T14:02:49 Z | coding_snorlax | Toy Train (IOI17_train) | C++14 | 0 ms | 0 KB |
#include<bits/stdc++.h> #include "wiring.h" using ll = long long int; using namespace std; ll dp[205][205]; long long int min_total_length(vector<int> r,vector<int> b){ long long int Count=0; dp[0][0]=abs(r[0]-b[0]); for(ll i=1;i<(ll)r.size();i++){ dp[i][0]=dp[i-1][0]+r[i]; } for(ll i=1;i<(ll)b.size();i++){ dp[0][i]=dp[0][i-1]+b[i]; } for(ll i=1;i<(ll)r.size();i++){ for(ll j=1;j<(ll)b.size();j++){ dp[i][j]=min(min(dp[i-1][j],dp[i][j-1]),dp[i-1][j-1])+abs(r[i]-b[j]); } } /* for(int i=0;i<(int)r.size();i++){ for(int j=0;j<(int)b.size();j++){ cout<<dp[i][j]<<" "; } cout<<"\n"; }*/ return dp[(ll)r.size()-1][(ll)b.size()-1]; }