제출 #569492

#제출 시각아이디문제언어결과실행 시간메모리
569492Turkhuu도로 폐쇄 (APIO21_roads)C++17
5 / 100
50 ms7436 KiB
#include "roads.h" #include <bits/stdc++.h> std::vector<long long> minimum_closure_costs(int n, std::vector<int> u, std::vector<int> v, std::vector<int> w){ bool subtask1 = true; for(int i = 0; i < n - 1; i++){ if(u[i] != 0){ subtask1 = false; } } if(subtask1){ sort(w.begin(), w.end()); std::vector<long long> ans(n); for(int i = 0; i < n - 1; i++){ ans[n - i - 2] = ans[n - i - 1] + w[i]; } return ans; } bool subtask2 = true; for(int i = 0; i < n - 1; i++){ if(u[i] != i || v[i] != i + 1){ subtask2 = false; } } if(subtask2){ std::vector<long long> ans(n); ans[0] = accumulate(w.begin(), w.end(), 0LL); std::vector<std::vector<long long>> dp(n, std::vector<long long>(2)); for(int i = 0; i < n - 1; i++){ dp[i][0] = (i == 0 ? 0 : std::min(dp[i - 1][0], dp[i - 1][1])) + w[i]; dp[i][1] = (i == 0 ? 0 : dp[i - 1][0]) + w[i]; } ans[1] = std::min(dp.back()[0], dp.back()[1]); return ans; } return std::vector<long long>(n, 0); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...