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;
const int N = 500;
vector<int> r , b;
long long dp[N][N];
int n , m;
long long solve(int i,int j){
if(i == n && j == m) return 0;
if(j == m) return 1e18;
if(dp[i][j] != -1) return dp[i][j];
dp[i][j] = min(solve(i+1,j),min(solve(i,j+1),solve(i+1,j+1))) + abs(r[i] - b[j]);
return dp[i][j];
}
long long min_total_length(std::vector<int> R, std::vector<int> B) {
memset(dp,-1,sizeof(dp));
r = R;
b = B;
n = r.size();
m = b.size();
return solve(0,0);
}
# | 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... |