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"
using namespace std;
const int MN = 2e5 + 3;
long long min_total_length (vector<int> r, vector<int> b) {
vector<vector<long long>> dp((int)r.size() + 1, vector<long long>((int)b.size() + 1,1e18));
dp[0][0] = 0; sort(r.begin(),r.end()); sort(b.begin(),b.end());
for (int i = 1; i <= (int)r.size(); i++) {
for (int j = 1; j <= (int)b.size(); j++) {
dp[i][j] = abs(r[i-1] - b[j-1]) + min({dp[i-1][j-1],dp[i-1][j],dp[i][j-1]});
}
}
return dp[(int)r.size()][(int)b.size()];
}
# | 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... |