답안 #256861

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
256861 2020-08-03T10:16:57 Z Goolakh Fireworks (APIO16_fireworks) C++17
100 / 100
241 ms 66296 KB
// FUCKED UP FUCKED UP FUCKED UP FUCKED UP FUCKED UP
#include <bits/stdc++.h>
using namespace std;

#pragma GCC optimize("O2,no-stack-protector,unroll-loops,fast-math")

#define F first
#define S second
#define pb push_back
#define SZ(x) (ll)(x.size())
#define all(x) x.begin(),x.end()
#define MP make_pair

typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;

//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const ll maxn=3e5+10, maxm=5e4+10, lg=21, mod=998244353, inf=1e18;

#define pq priority_queue<ll>

ll n,m,w[maxn],rr;
vector<ll> g[maxn];

pq dff(ll v=0){
	pq q;
	if(v<n){
		for(auto u:g[v]){
			pq p=dff(u);
			if(SZ(q)<SZ(p)) swap(p,q);
			while(!p.empty()) q.push(p.top()), p.pop();
		}
		for(int i=1;i<SZ(g[v]);i++) q.pop();
		ll x=q.top()+w[v]; q.pop();
		ll y=q.top()+w[v]; q.pop();
		q.push(x), q.push(y);
	}
	else q.push(w[v]), q.push(w[v]);
	return q;
}

int main(){
	ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	
	cin>>n>>m;
	for(int i=1,x;i<n+m;i++){
		cin>>x>>w[i]; rr+=w[i];
		g[--x].pb(i);
	}
	pq q=dff();
	ll p=q.top(); q.pop();
	ll tt=0;
	while(!q.empty()) rr-=tt++*(p-q.top()), p=q.top(), q.pop();
	cout<<rr-tt*p;
	
	return 0;
}



 
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 7424 KB Output is correct
2 Correct 6 ms 7424 KB Output is correct
3 Correct 5 ms 7424 KB Output is correct
4 Correct 5 ms 7424 KB Output is correct
5 Correct 5 ms 7424 KB Output is correct
6 Correct 7 ms 7424 KB Output is correct
7 Correct 5 ms 7424 KB Output is correct
8 Correct 5 ms 7424 KB Output is correct
9 Correct 6 ms 7424 KB Output is correct
10 Correct 6 ms 7424 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 7424 KB Output is correct
2 Correct 5 ms 7424 KB Output is correct
3 Correct 5 ms 7424 KB Output is correct
4 Correct 6 ms 7424 KB Output is correct
5 Correct 8 ms 7424 KB Output is correct
6 Correct 5 ms 7424 KB Output is correct
7 Correct 5 ms 7424 KB Output is correct
8 Correct 6 ms 7424 KB Output is correct
9 Correct 6 ms 7424 KB Output is correct
10 Correct 5 ms 7424 KB Output is correct
11 Correct 5 ms 7424 KB Output is correct
12 Correct 5 ms 7424 KB Output is correct
13 Correct 5 ms 7424 KB Output is correct
14 Correct 6 ms 7424 KB Output is correct
15 Correct 5 ms 7424 KB Output is correct
16 Correct 6 ms 7424 KB Output is correct
17 Correct 5 ms 7424 KB Output is correct
18 Correct 8 ms 7424 KB Output is correct
19 Correct 5 ms 7424 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 7424 KB Output is correct
2 Correct 6 ms 7424 KB Output is correct
3 Correct 5 ms 7424 KB Output is correct
4 Correct 5 ms 7424 KB Output is correct
5 Correct 5 ms 7424 KB Output is correct
6 Correct 7 ms 7424 KB Output is correct
7 Correct 5 ms 7424 KB Output is correct
8 Correct 5 ms 7424 KB Output is correct
9 Correct 6 ms 7424 KB Output is correct
10 Correct 6 ms 7424 KB Output is correct
11 Correct 5 ms 7424 KB Output is correct
12 Correct 5 ms 7424 KB Output is correct
13 Correct 5 ms 7424 KB Output is correct
14 Correct 6 ms 7424 KB Output is correct
15 Correct 8 ms 7424 KB Output is correct
16 Correct 5 ms 7424 KB Output is correct
17 Correct 5 ms 7424 KB Output is correct
18 Correct 6 ms 7424 KB Output is correct
19 Correct 6 ms 7424 KB Output is correct
20 Correct 5 ms 7424 KB Output is correct
21 Correct 5 ms 7424 KB Output is correct
22 Correct 5 ms 7424 KB Output is correct
23 Correct 5 ms 7424 KB Output is correct
24 Correct 6 ms 7424 KB Output is correct
25 Correct 5 ms 7424 KB Output is correct
26 Correct 6 ms 7424 KB Output is correct
27 Correct 5 ms 7424 KB Output is correct
28 Correct 8 ms 7424 KB Output is correct
29 Correct 5 ms 7424 KB Output is correct
30 Correct 6 ms 7424 KB Output is correct
31 Correct 5 ms 7424 KB Output is correct
32 Correct 5 ms 7424 KB Output is correct
33 Correct 6 ms 7552 KB Output is correct
34 Correct 7 ms 7552 KB Output is correct
35 Correct 7 ms 7552 KB Output is correct
36 Correct 7 ms 7552 KB Output is correct
37 Correct 8 ms 7680 KB Output is correct
38 Correct 7 ms 7680 KB Output is correct
39 Correct 7 ms 7680 KB Output is correct
40 Correct 10 ms 8320 KB Output is correct
41 Correct 8 ms 8320 KB Output is correct
42 Correct 8 ms 7680 KB Output is correct
43 Correct 8 ms 7936 KB Output is correct
44 Correct 8 ms 7936 KB Output is correct
45 Correct 9 ms 7936 KB Output is correct
46 Correct 8 ms 7680 KB Output is correct
47 Correct 9 ms 7680 KB Output is correct
48 Correct 8 ms 7680 KB Output is correct
49 Correct 8 ms 7680 KB Output is correct
50 Correct 8 ms 7680 KB Output is correct
51 Correct 7 ms 7680 KB Output is correct
52 Correct 7 ms 7692 KB Output is correct
53 Correct 8 ms 7708 KB Output is correct
54 Correct 7 ms 7680 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 7424 KB Output is correct
2 Correct 6 ms 7424 KB Output is correct
3 Correct 5 ms 7424 KB Output is correct
4 Correct 5 ms 7424 KB Output is correct
5 Correct 5 ms 7424 KB Output is correct
6 Correct 7 ms 7424 KB Output is correct
7 Correct 5 ms 7424 KB Output is correct
8 Correct 5 ms 7424 KB Output is correct
9 Correct 6 ms 7424 KB Output is correct
10 Correct 6 ms 7424 KB Output is correct
11 Correct 5 ms 7424 KB Output is correct
12 Correct 5 ms 7424 KB Output is correct
13 Correct 5 ms 7424 KB Output is correct
14 Correct 6 ms 7424 KB Output is correct
15 Correct 8 ms 7424 KB Output is correct
16 Correct 5 ms 7424 KB Output is correct
17 Correct 5 ms 7424 KB Output is correct
18 Correct 6 ms 7424 KB Output is correct
19 Correct 6 ms 7424 KB Output is correct
20 Correct 5 ms 7424 KB Output is correct
21 Correct 5 ms 7424 KB Output is correct
22 Correct 5 ms 7424 KB Output is correct
23 Correct 5 ms 7424 KB Output is correct
24 Correct 6 ms 7424 KB Output is correct
25 Correct 5 ms 7424 KB Output is correct
26 Correct 6 ms 7424 KB Output is correct
27 Correct 5 ms 7424 KB Output is correct
28 Correct 8 ms 7424 KB Output is correct
29 Correct 5 ms 7424 KB Output is correct
30 Correct 6 ms 7424 KB Output is correct
31 Correct 5 ms 7424 KB Output is correct
32 Correct 5 ms 7424 KB Output is correct
33 Correct 6 ms 7552 KB Output is correct
34 Correct 7 ms 7552 KB Output is correct
35 Correct 7 ms 7552 KB Output is correct
36 Correct 7 ms 7552 KB Output is correct
37 Correct 8 ms 7680 KB Output is correct
38 Correct 7 ms 7680 KB Output is correct
39 Correct 7 ms 7680 KB Output is correct
40 Correct 10 ms 8320 KB Output is correct
41 Correct 8 ms 8320 KB Output is correct
42 Correct 8 ms 7680 KB Output is correct
43 Correct 8 ms 7936 KB Output is correct
44 Correct 8 ms 7936 KB Output is correct
45 Correct 9 ms 7936 KB Output is correct
46 Correct 8 ms 7680 KB Output is correct
47 Correct 9 ms 7680 KB Output is correct
48 Correct 8 ms 7680 KB Output is correct
49 Correct 8 ms 7680 KB Output is correct
50 Correct 8 ms 7680 KB Output is correct
51 Correct 7 ms 7680 KB Output is correct
52 Correct 7 ms 7692 KB Output is correct
53 Correct 8 ms 7708 KB Output is correct
54 Correct 7 ms 7680 KB Output is correct
55 Correct 12 ms 8064 KB Output is correct
56 Correct 33 ms 10040 KB Output is correct
57 Correct 61 ms 11848 KB Output is correct
58 Correct 74 ms 13136 KB Output is correct
59 Correct 107 ms 14748 KB Output is correct
60 Correct 141 ms 16180 KB Output is correct
61 Correct 151 ms 18104 KB Output is correct
62 Correct 196 ms 19040 KB Output is correct
63 Correct 241 ms 20840 KB Output is correct
64 Correct 235 ms 21336 KB Output is correct
65 Correct 142 ms 66296 KB Output is correct
66 Correct 135 ms 66296 KB Output is correct
67 Correct 131 ms 24184 KB Output is correct
68 Correct 194 ms 42472 KB Output is correct
69 Correct 218 ms 39788 KB Output is correct
70 Correct 219 ms 39788 KB Output is correct
71 Correct 221 ms 22052 KB Output is correct
72 Correct 225 ms 21980 KB Output is correct
73 Correct 202 ms 21220 KB Output is correct
74 Correct 205 ms 21212 KB Output is correct
75 Correct 203 ms 20660 KB Output is correct
76 Correct 207 ms 20652 KB Output is correct
77 Correct 214 ms 21452 KB Output is correct
78 Correct 213 ms 21324 KB Output is correct
79 Correct 204 ms 23908 KB Output is correct