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;
typedef long long ll;
#define MAX 1010
vector<ll> R, B;
ll N, M;
ll dp[MAX][MAX];
long long min_total_length(vector<int> r, vector<int> b) {
ll i, j;
N = r.size();
M = b.size();
R.push_back(0);
B.push_back(0);
for (i = 0; i < N; i++) R.push_back((ll)r[i]);
for (i = 0; i < M; i++) B.push_back((ll)b[i]);
for (i = 1; i <= N; i++) {
for (j = 1; j <= M; j++) {
if (i == 1 || j == 1) dp[i][j] = dp[i - 1][j - 1] + abs(R[i] - B[j]);
else dp[i][j] = min(dp[i - 1][j - 1], min(dp[i - 1][j], dp[i][j - 1])) + abs(R[i] - B[j]);
}
}
return dp[N][M];
}
# | 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... |