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;
typedef long long ll;
const ll INF = 1e18;
ll min_total_length(vector<int> r, vector<int> b) {
int n = int(r.size()), m = int(b.size());
vector<ll> dp(m+1, INF);
dp[0] = 0;
for(int i = 0; i < n; i++){
vector<ll> dp2(m+1, INF);
for(int j = 1; j <= m; j++){
dp2[j] = min(dp2[j], dp[j]+abs(b[j-1]-r[i]));
ll cost = 0;
for(int k = j-1; k >= 0; k--){
cost += abs(b[k]-r[i]);
dp2[j] = min(dp2[j], dp[k]+cost);
}
// cerr << i << " " << j << " " << dp2[j] << "\n";
}
dp = dp2;
}
return dp[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... |