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;
#define ll long long
#define all(aaa) aaa.begin(), aaa.end()
const ll INF = 1e18;
const int N = 205;
ll dp[N][N];
void upd(ll &a, ll b) {
a = min(a, b);
}
ll min_total_length(vector<int> r, vector<int> b) {
int n = r.size(), m = b.size();
if (true) {
ll ans = 0;
if (n < m) {
for (int i = 0; i < n; i++)
ans += b[i] - r[i];
for (int i = n; i < m; i++)
ans += b[i] - r[n - 1];
}
else {
for (int i = 0; i < m; i++)
ans += b[i] - r[i];
for (int i = m; i < n; i++)
ans += b[0] - r[i];
}
return ans;
}
else {
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
dp[i][j] = INF;
}
}
dp[0][0] = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
ll val = dp[i][j] + abs(r[i] - b[j]);
upd(dp[i + 1][j], val);
upd(dp[i][j + 1], val);
upd(dp[i + 1][j + 1], val);
}
}
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... |