이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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... |