# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
46979 | 2018-04-25T16:13:20 Z | ngkan146 | Fireworks (APIO16_fireworks) | C++11 | 21 ms | 18516 KB |
#include <bits/stdc++.h> #define ll long long using namespace std; int n,m; ll c[300005]; priority_queue<ll> slope[300005]; vector <ll> G[300005]; ll val[300005]; // numkid = startslope ? void dfs(int u){ if (u > n){ return; } for(auto v: G[u]){ dfs(v); val[u] += val[v] + c[v]; if (v > n){ slope[v].push(c[v]); slope[v].push(c[v]); } else{ ll x = slope[v].top(); slope[v].pop(); ll y = slope[v].top(); slope[v].pop(); slope[v].push(x + c[v]); slope[v].push(y + c[v]); } } for(auto v: G[u]){ if (slope[v].size() > slope[u].size()) slope[u].swap(slope[v]); } for(auto v: G[u]){ while(slope[v].size()) slope[u].push(slope[v].top()), slope[v].pop(); } for(int _=0;_<G[u].size()-1;_++) slope[u].pop(); } int main(){ iostream::sync_with_stdio(0); cin >> n >> m; for(int i=2;i<=n+m;i++){ int p; cin >> p >> c[i]; G[p].push_back(i); } dfs(1); vector <int> mjk; while(!slope[1].empty()){ mjk.push_back(slope[1].top()); slope[1].pop(); } mjk.push_back(0); reverse(mjk.begin(), mjk.end()); for(int i=1;i<mjk.size();i++){ val[1] -= 1ll * (m+1-i) * (mjk[i] - mjk[i-1]); } cout << val[1]; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 14 ms | 16760 KB | Output is correct |
2 | Correct | 15 ms | 16868 KB | Output is correct |
3 | Correct | 15 ms | 16920 KB | Output is correct |
4 | Correct | 15 ms | 17124 KB | Output is correct |
5 | Correct | 15 ms | 17124 KB | Output is correct |
6 | Correct | 14 ms | 17124 KB | Output is correct |
7 | Correct | 14 ms | 17124 KB | Output is correct |
8 | Correct | 16 ms | 17124 KB | Output is correct |
9 | Correct | 15 ms | 17124 KB | Output is correct |
10 | Correct | 15 ms | 17124 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 15 ms | 17124 KB | Output is correct |
2 | Correct | 15 ms | 17124 KB | Output is correct |
3 | Correct | 15 ms | 17124 KB | Output is correct |
4 | Correct | 14 ms | 17124 KB | Output is correct |
5 | Correct | 19 ms | 17124 KB | Output is correct |
6 | Correct | 15 ms | 17124 KB | Output is correct |
7 | Correct | 19 ms | 17124 KB | Output is correct |
8 | Correct | 15 ms | 17124 KB | Output is correct |
9 | Correct | 15 ms | 17124 KB | Output is correct |
10 | Correct | 14 ms | 17216 KB | Output is correct |
11 | Correct | 16 ms | 17216 KB | Output is correct |
12 | Correct | 15 ms | 17216 KB | Output is correct |
13 | Correct | 16 ms | 17216 KB | Output is correct |
14 | Correct | 15 ms | 17216 KB | Output is correct |
15 | Correct | 18 ms | 17216 KB | Output is correct |
16 | Correct | 15 ms | 17216 KB | Output is correct |
17 | Correct | 15 ms | 17216 KB | Output is correct |
18 | Correct | 15 ms | 17216 KB | Output is correct |
19 | Correct | 15 ms | 17216 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 14 ms | 16760 KB | Output is correct |
2 | Correct | 15 ms | 16868 KB | Output is correct |
3 | Correct | 15 ms | 16920 KB | Output is correct |
4 | Correct | 15 ms | 17124 KB | Output is correct |
5 | Correct | 15 ms | 17124 KB | Output is correct |
6 | Correct | 14 ms | 17124 KB | Output is correct |
7 | Correct | 14 ms | 17124 KB | Output is correct |
8 | Correct | 16 ms | 17124 KB | Output is correct |
9 | Correct | 15 ms | 17124 KB | Output is correct |
10 | Correct | 15 ms | 17124 KB | Output is correct |
11 | Correct | 15 ms | 17124 KB | Output is correct |
12 | Correct | 15 ms | 17124 KB | Output is correct |
13 | Correct | 15 ms | 17124 KB | Output is correct |
14 | Correct | 14 ms | 17124 KB | Output is correct |
15 | Correct | 19 ms | 17124 KB | Output is correct |
16 | Correct | 15 ms | 17124 KB | Output is correct |
17 | Correct | 19 ms | 17124 KB | Output is correct |
18 | Correct | 15 ms | 17124 KB | Output is correct |
19 | Correct | 15 ms | 17124 KB | Output is correct |
20 | Correct | 14 ms | 17216 KB | Output is correct |
21 | Correct | 16 ms | 17216 KB | Output is correct |
22 | Correct | 15 ms | 17216 KB | Output is correct |
23 | Correct | 16 ms | 17216 KB | Output is correct |
24 | Correct | 15 ms | 17216 KB | Output is correct |
25 | Correct | 18 ms | 17216 KB | Output is correct |
26 | Correct | 15 ms | 17216 KB | Output is correct |
27 | Correct | 15 ms | 17216 KB | Output is correct |
28 | Correct | 15 ms | 17216 KB | Output is correct |
29 | Correct | 15 ms | 17216 KB | Output is correct |
30 | Correct | 15 ms | 17216 KB | Output is correct |
31 | Correct | 16 ms | 17216 KB | Output is correct |
32 | Correct | 16 ms | 17216 KB | Output is correct |
33 | Correct | 16 ms | 17364 KB | Output is correct |
34 | Correct | 17 ms | 17400 KB | Output is correct |
35 | Correct | 18 ms | 17636 KB | Output is correct |
36 | Correct | 18 ms | 17636 KB | Output is correct |
37 | Correct | 19 ms | 17840 KB | Output is correct |
38 | Correct | 19 ms | 17840 KB | Output is correct |
39 | Correct | 21 ms | 17904 KB | Output is correct |
40 | Incorrect | 18 ms | 18516 KB | Output isn't correct |
41 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 14 ms | 16760 KB | Output is correct |
2 | Correct | 15 ms | 16868 KB | Output is correct |
3 | Correct | 15 ms | 16920 KB | Output is correct |
4 | Correct | 15 ms | 17124 KB | Output is correct |
5 | Correct | 15 ms | 17124 KB | Output is correct |
6 | Correct | 14 ms | 17124 KB | Output is correct |
7 | Correct | 14 ms | 17124 KB | Output is correct |
8 | Correct | 16 ms | 17124 KB | Output is correct |
9 | Correct | 15 ms | 17124 KB | Output is correct |
10 | Correct | 15 ms | 17124 KB | Output is correct |
11 | Correct | 15 ms | 17124 KB | Output is correct |
12 | Correct | 15 ms | 17124 KB | Output is correct |
13 | Correct | 15 ms | 17124 KB | Output is correct |
14 | Correct | 14 ms | 17124 KB | Output is correct |
15 | Correct | 19 ms | 17124 KB | Output is correct |
16 | Correct | 15 ms | 17124 KB | Output is correct |
17 | Correct | 19 ms | 17124 KB | Output is correct |
18 | Correct | 15 ms | 17124 KB | Output is correct |
19 | Correct | 15 ms | 17124 KB | Output is correct |
20 | Correct | 14 ms | 17216 KB | Output is correct |
21 | Correct | 16 ms | 17216 KB | Output is correct |
22 | Correct | 15 ms | 17216 KB | Output is correct |
23 | Correct | 16 ms | 17216 KB | Output is correct |
24 | Correct | 15 ms | 17216 KB | Output is correct |
25 | Correct | 18 ms | 17216 KB | Output is correct |
26 | Correct | 15 ms | 17216 KB | Output is correct |
27 | Correct | 15 ms | 17216 KB | Output is correct |
28 | Correct | 15 ms | 17216 KB | Output is correct |
29 | Correct | 15 ms | 17216 KB | Output is correct |
30 | Correct | 15 ms | 17216 KB | Output is correct |
31 | Correct | 16 ms | 17216 KB | Output is correct |
32 | Correct | 16 ms | 17216 KB | Output is correct |
33 | Correct | 16 ms | 17364 KB | Output is correct |
34 | Correct | 17 ms | 17400 KB | Output is correct |
35 | Correct | 18 ms | 17636 KB | Output is correct |
36 | Correct | 18 ms | 17636 KB | Output is correct |
37 | Correct | 19 ms | 17840 KB | Output is correct |
38 | Correct | 19 ms | 17840 KB | Output is correct |
39 | Correct | 21 ms | 17904 KB | Output is correct |
40 | Incorrect | 18 ms | 18516 KB | Output isn't correct |
41 | Halted | 0 ms | 0 KB | - |