답안 #110542

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
110542 2019-05-11T06:46:19 Z Pro_ktmr Fireworks (APIO16_fireworks) C++14
55 / 100
2000 ms 208800 KB
#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);
	}
	void clear(){
		while(!pq.empty()) pq.pop();
	}
	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[300001], C[300001];
f node[300001];

int main(){
	scanf("%d%d", &N, &M);
	for(int i=2; i<=N+M; i++) scanf("%d%d", par+i, C+i);
	
	for(int i=N+M; 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];
		node[i].clear();
	}
	for(int i=N; 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];
		node[i].clear();
	}
	while(node[1].a > 0){ //最小のところでは傾きが0
		node[1].a--;
		node[1].b += node[1].pq.top();
		node[1].pq.pop();
	}
	printf("%lld\n", node[1].b);
}

Compilation message

fireworks.cpp: In function 'int main()':
fireworks.cpp:43:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d", &N, &M);
  ~~~~~^~~~~~~~~~~~~~~~
fireworks.cpp:44:33: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for(int i=2; i<=N+M; i++) scanf("%d%d", par+i, C+i);
                            ~~~~~^~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 14464 KB Output is correct
2 Correct 14 ms 14464 KB Output is correct
3 Correct 14 ms 14464 KB Output is correct
4 Correct 15 ms 14592 KB Output is correct
5 Correct 14 ms 14464 KB Output is correct
6 Correct 14 ms 14464 KB Output is correct
7 Correct 16 ms 14464 KB Output is correct
8 Correct 15 ms 14464 KB Output is correct
9 Correct 15 ms 14464 KB Output is correct
10 Correct 14 ms 14464 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 14464 KB Output is correct
2 Correct 15 ms 14464 KB Output is correct
3 Correct 12 ms 14464 KB Output is correct
4 Correct 16 ms 14464 KB Output is correct
5 Correct 16 ms 14464 KB Output is correct
6 Correct 15 ms 14464 KB Output is correct
7 Correct 18 ms 14464 KB Output is correct
8 Correct 16 ms 14376 KB Output is correct
9 Correct 16 ms 14464 KB Output is correct
10 Correct 15 ms 14364 KB Output is correct
11 Correct 16 ms 14464 KB Output is correct
12 Correct 16 ms 14464 KB Output is correct
13 Correct 15 ms 14464 KB Output is correct
14 Correct 15 ms 14464 KB Output is correct
15 Correct 15 ms 14464 KB Output is correct
16 Correct 17 ms 14464 KB Output is correct
17 Correct 16 ms 14436 KB Output is correct
18 Correct 18 ms 14464 KB Output is correct
19 Correct 16 ms 14464 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 14464 KB Output is correct
2 Correct 14 ms 14464 KB Output is correct
3 Correct 14 ms 14464 KB Output is correct
4 Correct 15 ms 14592 KB Output is correct
5 Correct 14 ms 14464 KB Output is correct
6 Correct 14 ms 14464 KB Output is correct
7 Correct 16 ms 14464 KB Output is correct
8 Correct 15 ms 14464 KB Output is correct
9 Correct 15 ms 14464 KB Output is correct
10 Correct 14 ms 14464 KB Output is correct
11 Correct 14 ms 14464 KB Output is correct
12 Correct 15 ms 14464 KB Output is correct
13 Correct 12 ms 14464 KB Output is correct
14 Correct 16 ms 14464 KB Output is correct
15 Correct 16 ms 14464 KB Output is correct
16 Correct 15 ms 14464 KB Output is correct
17 Correct 18 ms 14464 KB Output is correct
18 Correct 16 ms 14376 KB Output is correct
19 Correct 16 ms 14464 KB Output is correct
20 Correct 15 ms 14364 KB Output is correct
21 Correct 16 ms 14464 KB Output is correct
22 Correct 16 ms 14464 KB Output is correct
23 Correct 15 ms 14464 KB Output is correct
24 Correct 15 ms 14464 KB Output is correct
25 Correct 15 ms 14464 KB Output is correct
26 Correct 17 ms 14464 KB Output is correct
27 Correct 16 ms 14436 KB Output is correct
28 Correct 18 ms 14464 KB Output is correct
29 Correct 16 ms 14464 KB Output is correct
30 Correct 16 ms 14464 KB Output is correct
31 Correct 17 ms 14848 KB Output is correct
32 Correct 19 ms 14848 KB Output is correct
33 Correct 22 ms 14976 KB Output is correct
34 Correct 24 ms 15272 KB Output is correct
35 Correct 26 ms 16248 KB Output is correct
36 Correct 24 ms 16000 KB Output is correct
37 Correct 24 ms 15872 KB Output is correct
38 Correct 34 ms 18040 KB Output is correct
39 Correct 31 ms 16248 KB Output is correct
40 Correct 17 ms 14720 KB Output is correct
41 Correct 16 ms 14720 KB Output is correct
42 Correct 18 ms 14720 KB Output is correct
43 Correct 248 ms 60536 KB Output is correct
44 Correct 195 ms 51960 KB Output is correct
45 Correct 192 ms 51192 KB Output is correct
46 Correct 24 ms 15104 KB Output is correct
47 Correct 22 ms 15104 KB Output is correct
48 Correct 22 ms 14968 KB Output is correct
49 Correct 30 ms 14968 KB Output is correct
50 Correct 29 ms 14944 KB Output is correct
51 Correct 28 ms 14996 KB Output is correct
52 Correct 30 ms 15732 KB Output is correct
53 Correct 26 ms 15012 KB Output is correct
54 Correct 54 ms 15176 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 14464 KB Output is correct
2 Correct 14 ms 14464 KB Output is correct
3 Correct 14 ms 14464 KB Output is correct
4 Correct 15 ms 14592 KB Output is correct
5 Correct 14 ms 14464 KB Output is correct
6 Correct 14 ms 14464 KB Output is correct
7 Correct 16 ms 14464 KB Output is correct
8 Correct 15 ms 14464 KB Output is correct
9 Correct 15 ms 14464 KB Output is correct
10 Correct 14 ms 14464 KB Output is correct
11 Correct 14 ms 14464 KB Output is correct
12 Correct 15 ms 14464 KB Output is correct
13 Correct 12 ms 14464 KB Output is correct
14 Correct 16 ms 14464 KB Output is correct
15 Correct 16 ms 14464 KB Output is correct
16 Correct 15 ms 14464 KB Output is correct
17 Correct 18 ms 14464 KB Output is correct
18 Correct 16 ms 14376 KB Output is correct
19 Correct 16 ms 14464 KB Output is correct
20 Correct 15 ms 14364 KB Output is correct
21 Correct 16 ms 14464 KB Output is correct
22 Correct 16 ms 14464 KB Output is correct
23 Correct 15 ms 14464 KB Output is correct
24 Correct 15 ms 14464 KB Output is correct
25 Correct 15 ms 14464 KB Output is correct
26 Correct 17 ms 14464 KB Output is correct
27 Correct 16 ms 14436 KB Output is correct
28 Correct 18 ms 14464 KB Output is correct
29 Correct 16 ms 14464 KB Output is correct
30 Correct 16 ms 14464 KB Output is correct
31 Correct 17 ms 14848 KB Output is correct
32 Correct 19 ms 14848 KB Output is correct
33 Correct 22 ms 14976 KB Output is correct
34 Correct 24 ms 15272 KB Output is correct
35 Correct 26 ms 16248 KB Output is correct
36 Correct 24 ms 16000 KB Output is correct
37 Correct 24 ms 15872 KB Output is correct
38 Correct 34 ms 18040 KB Output is correct
39 Correct 31 ms 16248 KB Output is correct
40 Correct 17 ms 14720 KB Output is correct
41 Correct 16 ms 14720 KB Output is correct
42 Correct 18 ms 14720 KB Output is correct
43 Correct 248 ms 60536 KB Output is correct
44 Correct 195 ms 51960 KB Output is correct
45 Correct 192 ms 51192 KB Output is correct
46 Correct 24 ms 15104 KB Output is correct
47 Correct 22 ms 15104 KB Output is correct
48 Correct 22 ms 14968 KB Output is correct
49 Correct 30 ms 14968 KB Output is correct
50 Correct 29 ms 14944 KB Output is correct
51 Correct 28 ms 14996 KB Output is correct
52 Correct 30 ms 15732 KB Output is correct
53 Correct 26 ms 15012 KB Output is correct
54 Correct 54 ms 15176 KB Output is correct
55 Correct 85 ms 22876 KB Output is correct
56 Correct 553 ms 72868 KB Output is correct
57 Correct 1221 ms 136272 KB Output is correct
58 Correct 1328 ms 157296 KB Output is correct
59 Execution timed out 2061 ms 208800 KB Time limit exceeded
60 Halted 0 ms 0 KB -