Submission #588598

#TimeUsernameProblemLanguageResultExecution timeMemory
588598JomnoiRoad Closures (APIO21_roads)C++17
5 / 100
48 ms3884 KiB
#include <bits/stdc++.h> #include "roads.h" using namespace std; const int MAX_N = 1e5 + 5; const int INF = 1e9 + 7; int dp[MAX_N]; bool used[MAX_N]; vector <long long> minimum_closure_costs(int N, vector <int> U, vector <int> V, vector <int> W) { bool subtask1 = true, subtask2 = true; for(int i = 0; i < N - 1; i++) { if(U[i] != 0 and V[i] != 0) { subtask1 = false; } if(U[i] != i or V[i] != i + 1) { subtask2 = false; } } vector <long long> ans; if(subtask1 == true) { sort(W.rbegin(), W.rend()); long long sum = 0; for(int i = 0; i < N - 1; i++) { sum += W[i]; } for(int i = 0; i < N - 1; i++) { ans.push_back(sum); sum -= W[i]; } ans.push_back(0); } else if(subtask2 == true) { long long sum = 0; for(int i = 0; i < N - 1; i++) { sum += W[i]; } ans.push_back(sum); dp[0] = 0; for(int i = 1; i < N - 1; i++) { dp[i] = dp[i - 1] + W[i]; if(i == 1) { dp[i] = min(dp[i], W[i - 1]); } if(i - 2 >= 0) { dp[i] = min(dp[i], dp[i - 2] + W[i - 1]); } } ans.push_back(dp[N - 2]); for(int i = 0; i < N - 2; i++) { ans.push_back(0); } } else if(N <= 200) { // do something } else if(N <= 2000) { // do something } return ans; }
#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...