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;
const int MAX = 210;
long long dp[MAX][MAX];
int n, m;
long long min_total_length(std::vector<int> r, std::vector<int> b) {
n = r.size();
m = b.size();
for (int i = 0; i <= n; i++) {
for (int j = 0; j <= m; j++) {
dp[i][j] = 1e18;
}
}
dp[0][0] = 0;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
dp[i][j] = min(dp[i][j], dp[i - 1][j]);
dp[i][j] = min(dp[i][j], dp[i][j - 1]);
dp[i][j] = min(dp[i][j], dp[i - 1][j - 1]);
dp[i][j] += abs(r[i - 1] - b[j - 1]);
}
}
// for (int i = 0; i <= n; i++) {
// for (int j = 0; j <= m; j++) {
// if (dp[i][j] == 1e9) {
// cout << "- ";
// }
// else {
// cout << dp[i][j] << " ";
// }
// }
// cout << "\n";
// }
return dp[n][m];
}
//int main() {
// cin >> n >> m;
//
// vector <int> a;
// vector <int> b;
//
// int x;
// for (int i = 0; i < n; i++) {
// cin >> x;
// a.push_back(x);
// }
//
// for (int i = 0; i < m; i++) {
// cin >> x;
// b.push_back(x);
// }
//
// cout << min_total_length(a, b) << "\n";
//
// return 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... |