답안 #1105892

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1105892 2024-10-28T08:45:26 Z WeIlIaN Fireworks (APIO16_fireworks) C++14
100 / 100
143 ms 50996 KB
/*
 * Author: Gyeonggeun Kim(kriii)
 * Time Complexity: O(N lg^2 N)
 */
#include <stdio.h>
#include <algorithm>
#include <queue>
using namespace std;

const int maxn = 300003;

priority_queue<long long> *Q[maxn];
int N,M,V,P[maxn],C[maxn],D[maxn]; long long E[maxn];

int main()
{
	scanf ("%d %d",&N,&M);
	V = N + M;
	
	for (int i=2;i<=V;i++) scanf ("%d %d",&P[i],&C[i]);
	for (int i=1;i<=V;i++) Q[i] = new priority_queue<long long>;

	for (int i=V;i>=2;i--){
		long long p = 0, q = 0;
		if (D[i]){
			for (int j=1;j<D[i];j++){
				E[i] += Q[i]->top(); Q[i]->pop();
			}
			p = Q[i]->top(); Q[i]->pop();
			q = Q[i]->top(); Q[i]->pop();
		}
		Q[i]->push(p+C[i]);
		Q[i]->push(q+C[i]);
		E[i] -= C[i];

		priority_queue<long long> *&a = Q[i], *&b = Q[P[i]];
		if (a->size() > b->size()) swap(a,b);
		while (!a->empty()){
			b->push(a->top()); a->pop();
		}
		E[P[i]] += E[i];
		D[P[i]]++;
	}

	long long ans = E[1];
	for (int i=0;i<D[1];i++){
		ans += Q[1]->top(); Q[1]->pop();
	}
	printf ("%lld\n",ans);

	return 0;
}

Compilation message

fireworks.cpp: In function 'int main()':
fireworks.cpp:17:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   17 |  scanf ("%d %d",&N,&M);
      |  ~~~~~~^~~~~~~~~~~~~~~
fireworks.cpp:20:31: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   20 |  for (int i=2;i<=V;i++) scanf ("%d %d",&P[i],&C[i]);
      |                         ~~~~~~^~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4432 KB Output is correct
2 Correct 2 ms 4536 KB Output is correct
3 Correct 1 ms 4432 KB Output is correct
4 Correct 1 ms 4432 KB Output is correct
5 Correct 1 ms 4432 KB Output is correct
6 Correct 1 ms 4432 KB Output is correct
7 Correct 1 ms 4604 KB Output is correct
8 Correct 1 ms 4432 KB Output is correct
9 Correct 1 ms 4432 KB Output is correct
10 Correct 1 ms 4432 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4432 KB Output is correct
2 Correct 1 ms 4532 KB Output is correct
3 Correct 1 ms 4432 KB Output is correct
4 Correct 1 ms 4432 KB Output is correct
5 Correct 1 ms 4432 KB Output is correct
6 Correct 1 ms 4432 KB Output is correct
7 Correct 1 ms 4688 KB Output is correct
8 Correct 1 ms 4432 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4432 KB Output is correct
11 Correct 1 ms 4432 KB Output is correct
12 Correct 1 ms 4432 KB Output is correct
13 Correct 2 ms 4432 KB Output is correct
14 Correct 1 ms 4432 KB Output is correct
15 Correct 1 ms 4460 KB Output is correct
16 Correct 1 ms 4600 KB Output is correct
17 Correct 1 ms 4432 KB Output is correct
18 Correct 1 ms 4432 KB Output is correct
19 Correct 1 ms 4604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4432 KB Output is correct
2 Correct 2 ms 4536 KB Output is correct
3 Correct 1 ms 4432 KB Output is correct
4 Correct 1 ms 4432 KB Output is correct
5 Correct 1 ms 4432 KB Output is correct
6 Correct 1 ms 4432 KB Output is correct
7 Correct 1 ms 4604 KB Output is correct
8 Correct 1 ms 4432 KB Output is correct
9 Correct 1 ms 4432 KB Output is correct
10 Correct 1 ms 4432 KB Output is correct
11 Correct 1 ms 4432 KB Output is correct
12 Correct 1 ms 4532 KB Output is correct
13 Correct 1 ms 4432 KB Output is correct
14 Correct 1 ms 4432 KB Output is correct
15 Correct 1 ms 4432 KB Output is correct
16 Correct 1 ms 4432 KB Output is correct
17 Correct 1 ms 4688 KB Output is correct
18 Correct 1 ms 4432 KB Output is correct
19 Correct 1 ms 4444 KB Output is correct
20 Correct 1 ms 4432 KB Output is correct
21 Correct 1 ms 4432 KB Output is correct
22 Correct 1 ms 4432 KB Output is correct
23 Correct 2 ms 4432 KB Output is correct
24 Correct 1 ms 4432 KB Output is correct
25 Correct 1 ms 4460 KB Output is correct
26 Correct 1 ms 4600 KB Output is correct
27 Correct 1 ms 4432 KB Output is correct
28 Correct 1 ms 4432 KB Output is correct
29 Correct 1 ms 4604 KB Output is correct
30 Correct 1 ms 4600 KB Output is correct
31 Correct 1 ms 4432 KB Output is correct
32 Correct 1 ms 4688 KB Output is correct
33 Correct 2 ms 4688 KB Output is correct
34 Correct 2 ms 4688 KB Output is correct
35 Correct 2 ms 4688 KB Output is correct
36 Correct 2 ms 4944 KB Output is correct
37 Correct 3 ms 5116 KB Output is correct
38 Correct 3 ms 4944 KB Output is correct
39 Correct 3 ms 4944 KB Output is correct
40 Correct 2 ms 4688 KB Output is correct
41 Correct 2 ms 4688 KB Output is correct
42 Correct 2 ms 4688 KB Output is correct
43 Correct 3 ms 4944 KB Output is correct
44 Correct 3 ms 4952 KB Output is correct
45 Correct 3 ms 4864 KB Output is correct
46 Correct 3 ms 5372 KB Output is correct
47 Correct 4 ms 5256 KB Output is correct
48 Correct 3 ms 4944 KB Output is correct
49 Correct 4 ms 5104 KB Output is correct
50 Correct 2 ms 4944 KB Output is correct
51 Correct 3 ms 4844 KB Output is correct
52 Correct 3 ms 4944 KB Output is correct
53 Correct 3 ms 4944 KB Output is correct
54 Correct 3 ms 4944 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4432 KB Output is correct
2 Correct 2 ms 4536 KB Output is correct
3 Correct 1 ms 4432 KB Output is correct
4 Correct 1 ms 4432 KB Output is correct
5 Correct 1 ms 4432 KB Output is correct
6 Correct 1 ms 4432 KB Output is correct
7 Correct 1 ms 4604 KB Output is correct
8 Correct 1 ms 4432 KB Output is correct
9 Correct 1 ms 4432 KB Output is correct
10 Correct 1 ms 4432 KB Output is correct
11 Correct 1 ms 4432 KB Output is correct
12 Correct 1 ms 4532 KB Output is correct
13 Correct 1 ms 4432 KB Output is correct
14 Correct 1 ms 4432 KB Output is correct
15 Correct 1 ms 4432 KB Output is correct
16 Correct 1 ms 4432 KB Output is correct
17 Correct 1 ms 4688 KB Output is correct
18 Correct 1 ms 4432 KB Output is correct
19 Correct 1 ms 4444 KB Output is correct
20 Correct 1 ms 4432 KB Output is correct
21 Correct 1 ms 4432 KB Output is correct
22 Correct 1 ms 4432 KB Output is correct
23 Correct 2 ms 4432 KB Output is correct
24 Correct 1 ms 4432 KB Output is correct
25 Correct 1 ms 4460 KB Output is correct
26 Correct 1 ms 4600 KB Output is correct
27 Correct 1 ms 4432 KB Output is correct
28 Correct 1 ms 4432 KB Output is correct
29 Correct 1 ms 4604 KB Output is correct
30 Correct 1 ms 4600 KB Output is correct
31 Correct 1 ms 4432 KB Output is correct
32 Correct 1 ms 4688 KB Output is correct
33 Correct 2 ms 4688 KB Output is correct
34 Correct 2 ms 4688 KB Output is correct
35 Correct 2 ms 4688 KB Output is correct
36 Correct 2 ms 4944 KB Output is correct
37 Correct 3 ms 5116 KB Output is correct
38 Correct 3 ms 4944 KB Output is correct
39 Correct 3 ms 4944 KB Output is correct
40 Correct 2 ms 4688 KB Output is correct
41 Correct 2 ms 4688 KB Output is correct
42 Correct 2 ms 4688 KB Output is correct
43 Correct 3 ms 4944 KB Output is correct
44 Correct 3 ms 4952 KB Output is correct
45 Correct 3 ms 4864 KB Output is correct
46 Correct 3 ms 5372 KB Output is correct
47 Correct 4 ms 5256 KB Output is correct
48 Correct 3 ms 4944 KB Output is correct
49 Correct 4 ms 5104 KB Output is correct
50 Correct 2 ms 4944 KB Output is correct
51 Correct 3 ms 4844 KB Output is correct
52 Correct 3 ms 4944 KB Output is correct
53 Correct 3 ms 4944 KB Output is correct
54 Correct 3 ms 4944 KB Output is correct
55 Correct 5 ms 5712 KB Output is correct
56 Correct 27 ms 9808 KB Output is correct
57 Correct 31 ms 13664 KB Output is correct
58 Correct 40 ms 16336 KB Output is correct
59 Correct 52 ms 20276 KB Output is correct
60 Correct 64 ms 24004 KB Output is correct
61 Correct 79 ms 27072 KB Output is correct
62 Correct 90 ms 29628 KB Output is correct
63 Correct 127 ms 34568 KB Output is correct
64 Correct 131 ms 36156 KB Output is correct
65 Correct 63 ms 27464 KB Output is correct
66 Correct 68 ms 27556 KB Output is correct
67 Correct 59 ms 27464 KB Output is correct
68 Correct 99 ms 35004 KB Output is correct
69 Correct 108 ms 35776 KB Output is correct
70 Correct 120 ms 35780 KB Output is correct
71 Correct 136 ms 50864 KB Output is correct
72 Correct 133 ms 50996 KB Output is correct
73 Correct 120 ms 47640 KB Output is correct
74 Correct 138 ms 48144 KB Output is correct
75 Correct 122 ms 46400 KB Output is correct
76 Correct 133 ms 46476 KB Output is correct
77 Correct 143 ms 45620 KB Output is correct
78 Correct 135 ms 45240 KB Output is correct
79 Correct 121 ms 43444 KB Output is correct