제출 #569496

#제출 시각아이디문제언어결과실행 시간메모리
569496Turkhuu도로 폐쇄 (APIO21_roads)C++17
12 / 100
54 ms6456 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); for(int i = 0; i < n - 1; i++){ ans[0] += w[i]; } std::vector<long long> dp(n - 1); for(int i = 0; i < n - 1; i++){ dp[i] = std::min((i == 0 ? 0 : dp[i - 1]) + w[i], (i - 2 < 0 ? 0 : dp[i - 2]) + (i - 1 < 0 ? 0 : w[i - 1])); } ans[1] = dp.back(); 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...