# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
110535 | Pro_ktmr | Fireworks (APIO16_fireworks) | C++14 | 16 ms | 14464 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include"bits/stdc++.h"
using namespace std;
#define LL long long
#define PB push_back
#define MP make_pair
struct f{
LL a=0, b=0; //xが十分に大きいとき、f(x)=ax+b
priority_queue<LL> pq; //傾きが1変わる箇所(ダブりあり)
void push(LL x){
pq.push(x);
pq.push(x);
}
f operator+(f x){
f ret;
ret.a = a + x.a;
ret.b = b + x.b;
if(pq.size() > x.pq.size()){
ret.pq = pq;
while(!x.pq.empty()){
ret.pq.push(x.pq.top());
x.pq.pop();
}
}
else{
ret.pq = x.pq;
while(!pq.empty()){
ret.pq.push(pq.top());
pq.pop();
}
}
return ret;
}
};
int N, M, par[300000], C[300000];
f node[300000];
int main(){
scanf("%d%d", &N, &M);
for(int i=1; i<N+M; i++) scanf("%d%d", par+i, C+i);
for(int i=N+M-1; i>=N; i--){
node[i].a = 1;
node[i].b = -C[i];
node[i].push(C[i]);
node[par[i]] = node[par[i]] + node[i];
}
for(int i=N-1; i>=1; i--){
while(node[i].a > 1){ //傾きが1より大きい右の方は使わない
node[i].a--;
node[i].b += node[i].pq.top();
node[i].pq.pop();
}
//このノードと親との辺の情報を追加
LL tmp1 = node[i].pq.top();
node[i].pq.pop();
LL tmp0 = node[i].pq.top();
node[i].pq.pop();
node[i].pq.push(tmp0+C[i]);
node[i].pq.push(tmp1+C[i]);
node[i].b -= C[i];
node[par[i]] = node[par[i]] + node[i];
}
while(node[0].a > 0){ //最小のところでは傾きが0
node[0].a--;
node[0].b += node[0].pq.top();
node[0].pq.pop();
}
printf("%lld\n", node[0].b);
}
컴파일 시 표준 에러 (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... |