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 "roads.h"
#include <vector>
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
vector<ll> minimum_closure_costs(int n, vector<int> U, vector<int> V, vector<int> w) {
vector<ll> ans(n, ll(0));
// chain
// k = 0 --> close all roads
// k = 1 --> DP solution
// k >= 2 --> don't need to close any road, 0
ll cost = accumulate(w.begin(), w.end(), ll(0));
ans[0] = cost;
vector<vector<ll>> dp(n - 1, vector<ll>(2, (ll)0));
// dp[i][j]
dp[0][0] = 0;
dp[0][1] = w[0];
for (int i = 1; i < n - 1; i ++) {
dp[i][0] = dp[i-1][1];
dp[i][1] = w[i] + min(dp[i-1][1], dp[i-1][0]);
}
ans[1] = min(dp[n-2][0], dp[n-2][1]);
return ans;
}
# | 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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |