이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include "roads.h"
using namespace std;
#define ll long long
#define ff first
#define ss second
vector<ll> minimum_closure_costs(int n, vector<int> u, vector<int> u1, vector<int> w) {
vector <pair<ll,pair<ll,ll>>> v;
ll s = 0;
bool tr = 0;
for(int i = 0; i < n-1; i++){
v.push_back({w[i],{u[i],u1[i]}});
if(u1[i] != u[i]+1) tr = 1;
s += w[i];
}
vector <ll> v1;
sort(v.rbegin(), v.rend());
if(*max_element(u.begin(), u.end()) == 0){
ll s2 = s;
v1.push_back(s);
for(int i = 0; i < n-1; i++){
s2 -= (v[i].ff);
v1.push_back(s2);
}
return v1;
}
if(*max_element(w.begin(), w.end()) == 1){
vector <ll> p(n,0), v2, p1(n,0), v1;
for(int i = 0; i < n-1; i++){
p[u[i]]++;
p[u1[i]]++;
}
for(int i = 0; i < n; i++){
v2.push_back(p[i]);
}
sort(v2.begin(), v2.end());
p1[0] = v2[0];
for(int i = 1; i < n; i++){
p1[i] = p1[i-1] + v2[i];
}
int ind = 0;
for(int i = 0; i < n; i++){
while(v2[ind] <= i and ind < n){
ind++;
}
ll x = 0;
if(ind != 0) x = p[ind-1];
v1.push_back(p[n-1]-(x+(n-ind)*i));
}
return v1;
}
if(tr == 0){
v1.push_back(s);
vector <pair<int,int>> v2;
for(int i = 0; i < n-1; i++){
v2.push_back({u[i],w[i]});
}
sort(v2.begin(), v2.end());
vector <ll> p1(n+1,0), p2(n+1,0);
for(int i = 0; i < n-1; i++){
if(i > 0) p1[i] = p1[i-1], p2[i] = p2[i-1];
if(i % 2 == 0) p2[i] += v2[i].ss;
else p1[i] += v2[i].ss;
}
ll mx = max(p1[n-2],p2[n-2]);
for(int i = 0; i < n-2; i++){
mx = max(mx,p1[i]+p2[n-2]-p2[min(i+2,n-2)]);
mx = max(mx,p2[i]+p1[n-2]-p1[min(i+2,n-2)]);
}
v1.push_back(s-mx);
for(int i = 2; i < n; i++) v1.push_back(0);
return v1;
}
return vector<ll>(n-1,0);
}
# | 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... |