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"
using namespace std;
typedef vector<int> vi;
const int SMALL = 200;
const long long INF = 0x3f3f3f3f3f3f3f3f;
int abs_(int x) { return x > 0 ? x : -x; }
long long min(long long a, long long b) { return a < b ? a : b; }
long long dp[SMALL][SMALL];
long long min_total_length(vi aa, vi bb) {
int n = aa.size(), m = bb.size(), i, j;
for (i = 0; i < n; i++)
for (j = 0; j < m; j++) {
if (i == 0 && j == 0)
dp[i][j] = 0;
else {
dp[i][j] = INF;
if (i > 0)
dp[i][j] = min(dp[i][j], dp[i - 1][j]);
if (j > 0)
dp[i][j] = min(dp[i][j], dp[i][j - 1]);
if (i > 0 && j > 0)
dp[i][j] = min(dp[i][j], dp[i - 1][j - 1]);
}
dp[i][j] += abs_(aa[i] - bb[j]);
}
return dp[n - 1][m - 1];
}
# | 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... |