# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
430605 | asbsfds | Wiring (IOI17_wiring) | C++14 | 0 ms | 0 KiB |
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 <vector>
typedef long long llint;
const int maxn = 410;
llint dp[maxn][maxn];
llint min(llint a, llint b) {
if (a < b) return a;
return b;
}
long long min_total_length(std::vector<int> r, std::vector<int> b) {
for (int i = 0; i < r.size(); i++)
for (int j = 0; j < b.size(); j++)
dp[i][j] = (1LL << 60);
dp[0][0] = abs(r[0] - b[0]);
for (int i = 0; i < r.size(); i++) {
for (int j = 0; j < b.size(); j++) {
llint dis = abs(r[i] - b[j]);
if (i > 0) dp[i][j] = min(dp[i - 1][j] + dis, dp[i][j]);
if (j > 0) dp[i][j] = min(dp[i][j - 1] + dis, dp[i][j]);
if (i > 0 && j > 0) dp[i][j] = min(dp[i - 1][j - 1] + dis, dp[i][j]);
}
}
/**
for (int i = 0; i < r.size(); i++) {
for (int j = 0; j < b.size(); j++) {
printf("%d ", dp[i][j]);
}
printf("\n");
}
**/
return dp[r.size() - 1][b.size() - 1];
}