답안 #794257

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
794257 2023-07-26T11:30:44 Z IvanJ Fireworks (APIO16_fireworks) C++17
100 / 100
143 ms 58944 KB
#include<bits/stdc++.h>

#define pb push_back
#define x first
#define y second
#define all(a) (a).begin(), (a).end()

using namespace std;

typedef long long ll;
typedef pair<int, int> ii;

const int maxn = 3e5 + 5;

struct Data {
	ll a, b;
	priority_queue<ll> *s;
	
	Data operator +(Data d) {
		Data ret;
		ret.a = a + d.a;
		ret.b = b + d.b;
		if(s->size() > d.s->size()) {
			ret.s = s;
			while(d.s->size()) 	
				ret.s->push(d.s->top()), d.s->pop();
		} else {
			ret.s = d.s;
			while(s->size()) 
				ret.s->push(s->top()), s->pop();
		}
		return ret;
	}
	
	ll get_min() {
		while(a > 0)
			a--, b += s->top(), s->pop();
		return b;
	}
};

int n, m;
int p[maxn];
ll c[maxn];
Data D[maxn];
vector<pair<int, ll>> adj[maxn];

int main() {
	scanf("%d%d", &n, &m);
	for(int i = 1;i < n + m;i++)
		scanf("%d%lld", p + i, c + i), p[i]--;
	
	for(int i = 0;i < n + m;i++) 
		D[i].a = 0, D[i].b = 0, D[i].s = new priority_queue<ll>;
	
	for(int i = n;i < n + m;i++) {
		D[i].a = 1, D[i].b = -c[i];
		D[i].s->push(c[i]);
		D[i].s->push(c[i]);
		D[p[i]] = D[p[i]] + D[i];
	}
	
	for(int i = n - 1;i > 0;i--) {
		while(D[i].a > 1) {
			D[i].a--;
			D[i].b += D[i].s->top();
			D[i].s->pop();
		}
		ll x = D[i].s->top();D[i].s->pop();
		ll y = D[i].s->top();D[i].s->pop();
		D[i].s->push(x + c[i]);
		D[i].s->push(y + c[i]);
		D[i].b -= c[i];
		D[p[i]] = D[p[i]] + D[i];
	} 
	printf("%lld\n", D[0].get_min());
	return 0;
}

Compilation message

fireworks.cpp: In function 'int main()':
fireworks.cpp:49:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   49 |  scanf("%d%d", &n, &m);
      |  ~~~~~^~~~~~~~~~~~~~~~
fireworks.cpp:51:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   51 |   scanf("%d%lld", p + i, c + i), p[i]--;
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 7380 KB Output is correct
2 Correct 3 ms 7360 KB Output is correct
3 Correct 4 ms 7380 KB Output is correct
4 Correct 3 ms 7380 KB Output is correct
5 Correct 4 ms 7380 KB Output is correct
6 Correct 3 ms 7380 KB Output is correct
7 Correct 3 ms 7380 KB Output is correct
8 Correct 4 ms 7364 KB Output is correct
9 Correct 5 ms 7360 KB Output is correct
10 Correct 4 ms 7356 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 7360 KB Output is correct
2 Correct 4 ms 7380 KB Output is correct
3 Correct 3 ms 7380 KB Output is correct
4 Correct 5 ms 7360 KB Output is correct
5 Correct 4 ms 7380 KB Output is correct
6 Correct 4 ms 7380 KB Output is correct
7 Correct 3 ms 7352 KB Output is correct
8 Correct 4 ms 7356 KB Output is correct
9 Correct 3 ms 7380 KB Output is correct
10 Correct 4 ms 7380 KB Output is correct
11 Correct 4 ms 7356 KB Output is correct
12 Correct 5 ms 7360 KB Output is correct
13 Correct 4 ms 7356 KB Output is correct
14 Correct 4 ms 7380 KB Output is correct
15 Correct 4 ms 7360 KB Output is correct
16 Correct 4 ms 7380 KB Output is correct
17 Correct 4 ms 7380 KB Output is correct
18 Correct 3 ms 7360 KB Output is correct
19 Correct 4 ms 7380 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 7380 KB Output is correct
2 Correct 3 ms 7360 KB Output is correct
3 Correct 4 ms 7380 KB Output is correct
4 Correct 3 ms 7380 KB Output is correct
5 Correct 4 ms 7380 KB Output is correct
6 Correct 3 ms 7380 KB Output is correct
7 Correct 3 ms 7380 KB Output is correct
8 Correct 4 ms 7364 KB Output is correct
9 Correct 5 ms 7360 KB Output is correct
10 Correct 4 ms 7356 KB Output is correct
11 Correct 4 ms 7360 KB Output is correct
12 Correct 4 ms 7380 KB Output is correct
13 Correct 3 ms 7380 KB Output is correct
14 Correct 5 ms 7360 KB Output is correct
15 Correct 4 ms 7380 KB Output is correct
16 Correct 4 ms 7380 KB Output is correct
17 Correct 3 ms 7352 KB Output is correct
18 Correct 4 ms 7356 KB Output is correct
19 Correct 3 ms 7380 KB Output is correct
20 Correct 4 ms 7380 KB Output is correct
21 Correct 4 ms 7356 KB Output is correct
22 Correct 5 ms 7360 KB Output is correct
23 Correct 4 ms 7356 KB Output is correct
24 Correct 4 ms 7380 KB Output is correct
25 Correct 4 ms 7360 KB Output is correct
26 Correct 4 ms 7380 KB Output is correct
27 Correct 4 ms 7380 KB Output is correct
28 Correct 3 ms 7360 KB Output is correct
29 Correct 4 ms 7380 KB Output is correct
30 Correct 3 ms 7356 KB Output is correct
31 Correct 5 ms 7488 KB Output is correct
32 Correct 4 ms 7508 KB Output is correct
33 Correct 5 ms 7628 KB Output is correct
34 Correct 4 ms 7624 KB Output is correct
35 Correct 4 ms 7764 KB Output is correct
36 Correct 6 ms 7848 KB Output is correct
37 Correct 6 ms 7892 KB Output is correct
38 Correct 5 ms 7892 KB Output is correct
39 Correct 5 ms 8020 KB Output is correct
40 Correct 5 ms 7752 KB Output is correct
41 Correct 4 ms 7764 KB Output is correct
42 Correct 5 ms 7824 KB Output is correct
43 Correct 5 ms 7888 KB Output is correct
44 Correct 5 ms 7880 KB Output is correct
45 Correct 5 ms 7956 KB Output is correct
46 Correct 5 ms 8148 KB Output is correct
47 Correct 6 ms 8148 KB Output is correct
48 Correct 5 ms 8020 KB Output is correct
49 Correct 5 ms 8148 KB Output is correct
50 Correct 5 ms 8012 KB Output is correct
51 Correct 7 ms 8012 KB Output is correct
52 Correct 6 ms 8072 KB Output is correct
53 Correct 5 ms 8008 KB Output is correct
54 Correct 6 ms 8020 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 7380 KB Output is correct
2 Correct 3 ms 7360 KB Output is correct
3 Correct 4 ms 7380 KB Output is correct
4 Correct 3 ms 7380 KB Output is correct
5 Correct 4 ms 7380 KB Output is correct
6 Correct 3 ms 7380 KB Output is correct
7 Correct 3 ms 7380 KB Output is correct
8 Correct 4 ms 7364 KB Output is correct
9 Correct 5 ms 7360 KB Output is correct
10 Correct 4 ms 7356 KB Output is correct
11 Correct 4 ms 7360 KB Output is correct
12 Correct 4 ms 7380 KB Output is correct
13 Correct 3 ms 7380 KB Output is correct
14 Correct 5 ms 7360 KB Output is correct
15 Correct 4 ms 7380 KB Output is correct
16 Correct 4 ms 7380 KB Output is correct
17 Correct 3 ms 7352 KB Output is correct
18 Correct 4 ms 7356 KB Output is correct
19 Correct 3 ms 7380 KB Output is correct
20 Correct 4 ms 7380 KB Output is correct
21 Correct 4 ms 7356 KB Output is correct
22 Correct 5 ms 7360 KB Output is correct
23 Correct 4 ms 7356 KB Output is correct
24 Correct 4 ms 7380 KB Output is correct
25 Correct 4 ms 7360 KB Output is correct
26 Correct 4 ms 7380 KB Output is correct
27 Correct 4 ms 7380 KB Output is correct
28 Correct 3 ms 7360 KB Output is correct
29 Correct 4 ms 7380 KB Output is correct
30 Correct 3 ms 7356 KB Output is correct
31 Correct 5 ms 7488 KB Output is correct
32 Correct 4 ms 7508 KB Output is correct
33 Correct 5 ms 7628 KB Output is correct
34 Correct 4 ms 7624 KB Output is correct
35 Correct 4 ms 7764 KB Output is correct
36 Correct 6 ms 7848 KB Output is correct
37 Correct 6 ms 7892 KB Output is correct
38 Correct 5 ms 7892 KB Output is correct
39 Correct 5 ms 8020 KB Output is correct
40 Correct 5 ms 7752 KB Output is correct
41 Correct 4 ms 7764 KB Output is correct
42 Correct 5 ms 7824 KB Output is correct
43 Correct 5 ms 7888 KB Output is correct
44 Correct 5 ms 7880 KB Output is correct
45 Correct 5 ms 7956 KB Output is correct
46 Correct 5 ms 8148 KB Output is correct
47 Correct 6 ms 8148 KB Output is correct
48 Correct 5 ms 8020 KB Output is correct
49 Correct 5 ms 8148 KB Output is correct
50 Correct 5 ms 8012 KB Output is correct
51 Correct 7 ms 8012 KB Output is correct
52 Correct 6 ms 8072 KB Output is correct
53 Correct 5 ms 8008 KB Output is correct
54 Correct 6 ms 8020 KB Output is correct
55 Correct 8 ms 9020 KB Output is correct
56 Correct 21 ms 14012 KB Output is correct
57 Correct 34 ms 18600 KB Output is correct
58 Correct 46 ms 21796 KB Output is correct
59 Correct 61 ms 26456 KB Output is correct
60 Correct 87 ms 31164 KB Output is correct
61 Correct 92 ms 34876 KB Output is correct
62 Correct 102 ms 37516 KB Output is correct
63 Correct 128 ms 43328 KB Output is correct
64 Correct 142 ms 45104 KB Output is correct
65 Correct 69 ms 36808 KB Output is correct
66 Correct 79 ms 36928 KB Output is correct
67 Correct 68 ms 36812 KB Output is correct
68 Correct 113 ms 43552 KB Output is correct
69 Correct 118 ms 44240 KB Output is correct
70 Correct 120 ms 44124 KB Output is correct
71 Correct 143 ms 58932 KB Output is correct
72 Correct 139 ms 58944 KB Output is correct
73 Correct 123 ms 55484 KB Output is correct
74 Correct 125 ms 56036 KB Output is correct
75 Correct 127 ms 54200 KB Output is correct
76 Correct 127 ms 54436 KB Output is correct
77 Correct 134 ms 53576 KB Output is correct
78 Correct 135 ms 52920 KB Output is correct
79 Correct 129 ms 51880 KB Output is correct