This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |