# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
984200 | Alkaser_ID | Road Closures (APIO21_roads) | C++17 | 25 ms | 15964 KiB |
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"
using namespace std;
#include <bits/stdc++.h>
typedef long long ll;
vector<ll> adj[200005];
std::vector<long long> minimum_closure_costs(int N, std::vector<int> U,
std::vector<int> V,
std::vector<int> W) {
ll n = N;
bool sb1 = true, sb2 = true;
for(int i=0;i<n-1;i++) {
if(U[i] != 0) sb1 = false;
if(U[i] = i || V[i] != i+1) sb2 = false;
ll u,v;
adj[u].push_back(v);
adj[v].push_back(u);
}
if(sb1){
vector<ll> f;
for(ll i=0;i<n-1;++i) f.push_back(W[i]);
sort(f.begin(),f.end());
ll res = 0;
vector<ll> ans;
ans.push_back(res);
for(ll i=0;i<n-1;++i){
res += f[i];
ans.push_back(res);
}
return ans;
}
if(sb2){
ll sm =0;
for(ll i=0;i<n-1;++i) sm += W[i];
vector<ll> ans;
ans.push_back(sm);
vector<ll> dp0(n+3,0),dp1(n+3,0);
dp0[0] = 0; dp1[0] = W[0];
for(ll i=1;i<n-1;++i){
dp0[i] = dp1[i-1];
dp1[i] = min(dp0[i-1],dp1[i-1]) + W[i];
}
ans.push_back(min(dp0[n-1],dp1[n-1]));
for(ll i=2;i<n;++i) ans.push_back(0);
return ans;
}
}
Compilation message (stderr)
# | 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... |