# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
391911 | MilosMilutinovic | Wiring (IOI17_wiring) | C++14 | 29 ms | 3788 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.
/**
* author: milos
* created: 20.04.2021 07:58:08
**/
#include <bits/stdc++.h>
#include "wiring.h"
using namespace std;
long long min_total_length(vector<int> r, vector<int> b) {
int n = (int) r.size(), m = (int) b.size();
if (n <= 200 && m <= 200) {
const long long inf = 1e18;
vector<vector<long long>> dp(n + 1, vector<long long>(m + 1, inf));
dp[0][0] = 0LL;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
dp[i][j] = min({dp[i - 1][j - 1], dp[i - 1][j], dp[i][j - 1]}) + abs(r[i - 1] - b[j - 1]);
}
}
return dp[n][m];
}
if (r[n - 1] < b[0]) {
if (n < m) {
long long ans = 0;
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];
}
return ans;
} else {
long long ans = 0;
for (int i = 0; i < m; i++) {
ans += b[i] - r[n - m + i];
}
for (int i = 0; i < n - m; i++) {
ans += b[0] - r[i];
}
return ans;
}
}
}
Compilation message (stderr)
# | 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... |