답안 #254587

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
254587 2020-07-30T09:58:56 Z maximath_1 Fireworks (APIO16_fireworks) C++11
100 / 100
305 ms 70904 KB
#include<bits/stdc++.h>
using namespace std;
#define ll long long
struct slop{
	ll a, b;
	priority_queue<ll>pq;
	slop& operator+=(slop& x){
		a+=x.a; b+=x.b;
		if(x.pq.size()>pq.size())
			swap(pq, x.pq);
		for(;!x.pq.empty();x.pq.pop())
			pq.push(x.pq.top());
		return *this;
	}
}f[300005];
ll cst[300005];
vector<int>adj[300005];
void dfs(int nw){
	if(adj[nw].size()==0){ //leaf
		f[nw].a=1; f[nw].b=-cst[nw];
		f[nw].pq.push(cst[nw]);
		f[nw].pq.push(cst[nw]);
		return;
	}
	for(int nx:adj[nw]){
		dfs(nx);
		f[nw]+=f[nx];
	}
	//>1 useless, reduce
	for(;f[nw].a>1;){ 
		f[nw].a-=1;
		f[nw].b+=f[nw].pq.top();
		f[nw].pq.pop();
	}
	//shift 0 and 1
	ll fi=f[nw].pq.top()+cst[nw]; f[nw].pq.pop();
	ll sc=f[nw].pq.top()+cst[nw]; f[nw].pq.pop();
	f[nw].pq.push(fi); f[nw].pq.push(sc);
	//after shift, reduce b
	f[nw].b-=cst[nw];
}
int main(){
	int n, m; scanf("%d%d", &n, &m);
	for(int i=2, bf; i<=n+m; i++){
		scanf("%d%lld", &bf, &cst[i]);
		adj[bf].push_back(i);
	}
	dfs(1);
	printf("%lld\n", f[1].a*f[1].pq.top()+f[1].b);
	return 0;
}

Compilation message

fireworks.cpp: In function 'int main()':
fireworks.cpp:43:17: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  int n, m; scanf("%d%d", &n, &m);
            ~~~~~^~~~~~~~~~~~~~~~
fireworks.cpp:45:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%lld", &bf, &cst[i]);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 21504 KB Output is correct
2 Correct 12 ms 21504 KB Output is correct
3 Correct 12 ms 21504 KB Output is correct
4 Correct 12 ms 21504 KB Output is correct
5 Correct 12 ms 21504 KB Output is correct
6 Correct 15 ms 21504 KB Output is correct
7 Correct 12 ms 21504 KB Output is correct
8 Correct 12 ms 21504 KB Output is correct
9 Correct 12 ms 21504 KB Output is correct
10 Correct 12 ms 21504 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 21504 KB Output is correct
2 Correct 12 ms 21504 KB Output is correct
3 Correct 12 ms 21504 KB Output is correct
4 Correct 13 ms 21504 KB Output is correct
5 Correct 12 ms 21504 KB Output is correct
6 Correct 12 ms 21504 KB Output is correct
7 Correct 12 ms 21504 KB Output is correct
8 Correct 12 ms 21504 KB Output is correct
9 Correct 12 ms 21504 KB Output is correct
10 Correct 13 ms 21504 KB Output is correct
11 Correct 17 ms 21504 KB Output is correct
12 Correct 15 ms 21504 KB Output is correct
13 Correct 12 ms 21504 KB Output is correct
14 Correct 15 ms 21632 KB Output is correct
15 Correct 13 ms 21504 KB Output is correct
16 Correct 13 ms 21504 KB Output is correct
17 Correct 12 ms 21504 KB Output is correct
18 Correct 12 ms 21504 KB Output is correct
19 Correct 13 ms 21428 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 21504 KB Output is correct
2 Correct 12 ms 21504 KB Output is correct
3 Correct 12 ms 21504 KB Output is correct
4 Correct 12 ms 21504 KB Output is correct
5 Correct 12 ms 21504 KB Output is correct
6 Correct 15 ms 21504 KB Output is correct
7 Correct 12 ms 21504 KB Output is correct
8 Correct 12 ms 21504 KB Output is correct
9 Correct 12 ms 21504 KB Output is correct
10 Correct 12 ms 21504 KB Output is correct
11 Correct 11 ms 21504 KB Output is correct
12 Correct 12 ms 21504 KB Output is correct
13 Correct 12 ms 21504 KB Output is correct
14 Correct 13 ms 21504 KB Output is correct
15 Correct 12 ms 21504 KB Output is correct
16 Correct 12 ms 21504 KB Output is correct
17 Correct 12 ms 21504 KB Output is correct
18 Correct 12 ms 21504 KB Output is correct
19 Correct 12 ms 21504 KB Output is correct
20 Correct 13 ms 21504 KB Output is correct
21 Correct 17 ms 21504 KB Output is correct
22 Correct 15 ms 21504 KB Output is correct
23 Correct 12 ms 21504 KB Output is correct
24 Correct 15 ms 21632 KB Output is correct
25 Correct 13 ms 21504 KB Output is correct
26 Correct 13 ms 21504 KB Output is correct
27 Correct 12 ms 21504 KB Output is correct
28 Correct 12 ms 21504 KB Output is correct
29 Correct 13 ms 21428 KB Output is correct
30 Correct 13 ms 21504 KB Output is correct
31 Correct 14 ms 21504 KB Output is correct
32 Correct 16 ms 21632 KB Output is correct
33 Correct 14 ms 21636 KB Output is correct
34 Correct 16 ms 21624 KB Output is correct
35 Correct 15 ms 21760 KB Output is correct
36 Correct 16 ms 21760 KB Output is correct
37 Correct 15 ms 21760 KB Output is correct
38 Correct 17 ms 21888 KB Output is correct
39 Correct 18 ms 21760 KB Output is correct
40 Correct 14 ms 22272 KB Output is correct
41 Correct 17 ms 22272 KB Output is correct
42 Correct 16 ms 21760 KB Output is correct
43 Correct 15 ms 22016 KB Output is correct
44 Correct 16 ms 21888 KB Output is correct
45 Correct 16 ms 22016 KB Output is correct
46 Correct 17 ms 21888 KB Output is correct
47 Correct 17 ms 21888 KB Output is correct
48 Correct 17 ms 21760 KB Output is correct
49 Correct 17 ms 21888 KB Output is correct
50 Correct 14 ms 21760 KB Output is correct
51 Correct 15 ms 21760 KB Output is correct
52 Correct 14 ms 21760 KB Output is correct
53 Correct 17 ms 21888 KB Output is correct
54 Correct 17 ms 21888 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 21504 KB Output is correct
2 Correct 12 ms 21504 KB Output is correct
3 Correct 12 ms 21504 KB Output is correct
4 Correct 12 ms 21504 KB Output is correct
5 Correct 12 ms 21504 KB Output is correct
6 Correct 15 ms 21504 KB Output is correct
7 Correct 12 ms 21504 KB Output is correct
8 Correct 12 ms 21504 KB Output is correct
9 Correct 12 ms 21504 KB Output is correct
10 Correct 12 ms 21504 KB Output is correct
11 Correct 11 ms 21504 KB Output is correct
12 Correct 12 ms 21504 KB Output is correct
13 Correct 12 ms 21504 KB Output is correct
14 Correct 13 ms 21504 KB Output is correct
15 Correct 12 ms 21504 KB Output is correct
16 Correct 12 ms 21504 KB Output is correct
17 Correct 12 ms 21504 KB Output is correct
18 Correct 12 ms 21504 KB Output is correct
19 Correct 12 ms 21504 KB Output is correct
20 Correct 13 ms 21504 KB Output is correct
21 Correct 17 ms 21504 KB Output is correct
22 Correct 15 ms 21504 KB Output is correct
23 Correct 12 ms 21504 KB Output is correct
24 Correct 15 ms 21632 KB Output is correct
25 Correct 13 ms 21504 KB Output is correct
26 Correct 13 ms 21504 KB Output is correct
27 Correct 12 ms 21504 KB Output is correct
28 Correct 12 ms 21504 KB Output is correct
29 Correct 13 ms 21428 KB Output is correct
30 Correct 13 ms 21504 KB Output is correct
31 Correct 14 ms 21504 KB Output is correct
32 Correct 16 ms 21632 KB Output is correct
33 Correct 14 ms 21636 KB Output is correct
34 Correct 16 ms 21624 KB Output is correct
35 Correct 15 ms 21760 KB Output is correct
36 Correct 16 ms 21760 KB Output is correct
37 Correct 15 ms 21760 KB Output is correct
38 Correct 17 ms 21888 KB Output is correct
39 Correct 18 ms 21760 KB Output is correct
40 Correct 14 ms 22272 KB Output is correct
41 Correct 17 ms 22272 KB Output is correct
42 Correct 16 ms 21760 KB Output is correct
43 Correct 15 ms 22016 KB Output is correct
44 Correct 16 ms 21888 KB Output is correct
45 Correct 16 ms 22016 KB Output is correct
46 Correct 17 ms 21888 KB Output is correct
47 Correct 17 ms 21888 KB Output is correct
48 Correct 17 ms 21760 KB Output is correct
49 Correct 17 ms 21888 KB Output is correct
50 Correct 14 ms 21760 KB Output is correct
51 Correct 15 ms 21760 KB Output is correct
52 Correct 14 ms 21760 KB Output is correct
53 Correct 17 ms 21888 KB Output is correct
54 Correct 17 ms 21888 KB Output is correct
55 Correct 27 ms 22520 KB Output is correct
56 Correct 50 ms 24952 KB Output is correct
57 Correct 95 ms 27380 KB Output is correct
58 Correct 109 ms 28996 KB Output is correct
59 Correct 170 ms 31472 KB Output is correct
60 Correct 176 ms 34156 KB Output is correct
61 Correct 220 ms 36208 KB Output is correct
62 Correct 229 ms 37488 KB Output is correct
63 Correct 294 ms 40536 KB Output is correct
64 Correct 305 ms 41324 KB Output is correct
65 Correct 151 ms 70904 KB Output is correct
66 Correct 144 ms 70904 KB Output is correct
67 Correct 152 ms 38212 KB Output is correct
68 Correct 209 ms 55784 KB Output is correct
69 Correct 233 ms 53100 KB Output is correct
70 Correct 230 ms 53224 KB Output is correct
71 Correct 239 ms 50660 KB Output is correct
72 Correct 238 ms 51044 KB Output is correct
73 Correct 198 ms 47072 KB Output is correct
74 Correct 201 ms 47200 KB Output is correct
75 Correct 207 ms 46052 KB Output is correct
76 Correct 204 ms 46188 KB Output is correct
77 Correct 211 ms 45800 KB Output is correct
78 Correct 204 ms 43748 KB Output is correct
79 Correct 197 ms 45044 KB Output is correct