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>
#include "wiring.h"
#define F first
#define S second
#define pii pair <int, int>
#define pb push_back
using namespace std;
typedef long long ll;
const int maxN = 210;
const ll oo = 1e16;
ll dp[maxN][maxN];
long long min_total_length(std::vector<int> r, std::vector<int> b) {
int n = r.size(), m = b.size();
dp[0][0] = 0;
for (int j=1; j<=m; j++) dp[0][j] = oo;
for (int i=1; i<=n; i++) dp[i][0] = oo;
for (int i=1; i<=n; i++)
for (int j=1; j<=m; j++)
{
ll curr = 0;
dp[i][j] = oo;
for (int k=j-1; k>=0; k--)
{
curr += abs(r[i - 1] - b[k]);
dp[i][j] = min(dp[i][j], curr + dp[i - 1][k]);
}
curr = 0;
for (int k=i-1; k>=0; k--)
{
curr += abs(b[j - 1] - r[k]);
dp[i][j] = min(dp[i][j], curr + dp[k][j - 1]);
}
}
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... |