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>
#define int long long
using namespace std;
int min_total_length(vector<signed> r, vector<signed> b) {
int nbRouges = r.size();
int nbBleus = b.size();
vector<vector<int>> dp(nbRouges, vector<int>(nbBleus));
for (int iRouge = 0; iRouge < nbRouges; ++iRouge)
for (int iBleu = 0; iBleu < nbBleus; ++iBleu) {
dp[iRouge][iBleu] = abs(r[iRouge] - b[iBleu]);
int toAdd = 1e18;
if (!iRouge and !iBleu)
toAdd = 0;
if (iRouge and iBleu)
toAdd = min(toAdd, dp[iRouge - 1][iBleu - 1]);
if (iRouge)
toAdd = min(toAdd, dp[iRouge - 1][iBleu]);
if (iBleu)
toAdd = min(toAdd, dp[iRouge][iBleu - 1]);
dp[iRouge][iBleu] += toAdd;
// cout << iRouge << ' ' << iBleu << ' ' << dp[iRouge][iBleu] << endl;
}
return dp[nbRouges - 1][nbBleus - 1];
}
# | 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... |