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 <bits/stdc++.h>
using namespace std;
#include "wiring.h"
long long ara(long long a, long long b){
if (a>b) return a-b;
return b-a;
}
long long min_total_length(std::vector<int> r, std::vector<int> b) {
int n = r.size();
int m = b.size();
vector<vector<long long>> dp(n, vector<long long>(m,-1));
function<long long(int,int)> f;
f = [&](int x, int y)->long long{
if (dp[x][y]!=-1) return dp[x][y];
if (x==n-1 && y==m-1){
return ara(r[x],b[y]);
}
if (x==n-1){
return dp[x][y]=ara(r[x],b[y])+f(x,y+1);
}
if (y==m-1){
return dp[x][y]=ara(r[x],b[y])+f(x+1,y);
}
dp[x][y]=ara(r[x],b[y]);
long long mava = f(x+1,y+1);
mava=min(mava,f(x,y+1));
mava=min(mava,f(x+1,y));
return dp[x][y]+=mava;
};
return f(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... |