답안 #46980

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
46980 2018-04-25T16:14:48 Z ngkan146 Fireworks (APIO16_fireworks) C++11
100 / 100
348 ms 132212 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];
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 <ll> 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

fireworks.cpp: In function 'void dfs(int)':
fireworks.cpp:43:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int _=0;_<G[u].size()-1;_++)
                 ~^~~~~~~~~~~~~~
fireworks.cpp: In function 'int main()':
fireworks.cpp:63:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=1;i<mjk.size();i++){
                 ~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 16760 KB Output is correct
2 Correct 15 ms 16868 KB Output is correct
3 Correct 16 ms 16868 KB Output is correct
4 Correct 15 ms 17096 KB Output is correct
5 Correct 15 ms 17096 KB Output is correct
6 Correct 15 ms 17096 KB Output is correct
7 Correct 15 ms 17096 KB Output is correct
8 Correct 15 ms 17096 KB Output is correct
9 Correct 16 ms 17096 KB Output is correct
10 Correct 15 ms 17096 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 17096 KB Output is correct
2 Correct 14 ms 17096 KB Output is correct
3 Correct 15 ms 17096 KB Output is correct
4 Correct 16 ms 17096 KB Output is correct
5 Correct 14 ms 17096 KB Output is correct
6 Correct 16 ms 17096 KB Output is correct
7 Correct 15 ms 17096 KB Output is correct
8 Correct 15 ms 17096 KB Output is correct
9 Correct 15 ms 17096 KB Output is correct
10 Correct 15 ms 17096 KB Output is correct
11 Correct 14 ms 17096 KB Output is correct
12 Correct 15 ms 17148 KB Output is correct
13 Correct 16 ms 17148 KB Output is correct
14 Correct 15 ms 17148 KB Output is correct
15 Correct 14 ms 17148 KB Output is correct
16 Correct 15 ms 17148 KB Output is correct
17 Correct 14 ms 17148 KB Output is correct
18 Correct 15 ms 17148 KB Output is correct
19 Correct 14 ms 17148 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 16760 KB Output is correct
2 Correct 15 ms 16868 KB Output is correct
3 Correct 16 ms 16868 KB Output is correct
4 Correct 15 ms 17096 KB Output is correct
5 Correct 15 ms 17096 KB Output is correct
6 Correct 15 ms 17096 KB Output is correct
7 Correct 15 ms 17096 KB Output is correct
8 Correct 15 ms 17096 KB Output is correct
9 Correct 16 ms 17096 KB Output is correct
10 Correct 15 ms 17096 KB Output is correct
11 Correct 15 ms 17096 KB Output is correct
12 Correct 14 ms 17096 KB Output is correct
13 Correct 15 ms 17096 KB Output is correct
14 Correct 16 ms 17096 KB Output is correct
15 Correct 14 ms 17096 KB Output is correct
16 Correct 16 ms 17096 KB Output is correct
17 Correct 15 ms 17096 KB Output is correct
18 Correct 15 ms 17096 KB Output is correct
19 Correct 15 ms 17096 KB Output is correct
20 Correct 15 ms 17096 KB Output is correct
21 Correct 14 ms 17096 KB Output is correct
22 Correct 15 ms 17148 KB Output is correct
23 Correct 16 ms 17148 KB Output is correct
24 Correct 15 ms 17148 KB Output is correct
25 Correct 14 ms 17148 KB Output is correct
26 Correct 15 ms 17148 KB Output is correct
27 Correct 14 ms 17148 KB Output is correct
28 Correct 15 ms 17148 KB Output is correct
29 Correct 14 ms 17148 KB Output is correct
30 Correct 16 ms 17148 KB Output is correct
31 Correct 15 ms 17148 KB Output is correct
32 Correct 18 ms 17148 KB Output is correct
33 Correct 16 ms 17148 KB Output is correct
34 Correct 17 ms 17276 KB Output is correct
35 Correct 17 ms 17276 KB Output is correct
36 Correct 23 ms 17276 KB Output is correct
37 Correct 18 ms 17404 KB Output is correct
38 Correct 19 ms 17404 KB Output is correct
39 Correct 18 ms 17404 KB Output is correct
40 Correct 17 ms 17916 KB Output is correct
41 Correct 17 ms 17948 KB Output is correct
42 Correct 18 ms 17948 KB Output is correct
43 Correct 19 ms 17948 KB Output is correct
44 Correct 19 ms 17948 KB Output is correct
45 Correct 20 ms 18084 KB Output is correct
46 Correct 20 ms 18120 KB Output is correct
47 Correct 19 ms 18200 KB Output is correct
48 Correct 18 ms 18200 KB Output is correct
49 Correct 18 ms 18200 KB Output is correct
50 Correct 18 ms 18200 KB Output is correct
51 Correct 17 ms 18200 KB Output is correct
52 Correct 18 ms 18372 KB Output is correct
53 Correct 19 ms 18432 KB Output is correct
54 Correct 23 ms 18500 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 16760 KB Output is correct
2 Correct 15 ms 16868 KB Output is correct
3 Correct 16 ms 16868 KB Output is correct
4 Correct 15 ms 17096 KB Output is correct
5 Correct 15 ms 17096 KB Output is correct
6 Correct 15 ms 17096 KB Output is correct
7 Correct 15 ms 17096 KB Output is correct
8 Correct 15 ms 17096 KB Output is correct
9 Correct 16 ms 17096 KB Output is correct
10 Correct 15 ms 17096 KB Output is correct
11 Correct 15 ms 17096 KB Output is correct
12 Correct 14 ms 17096 KB Output is correct
13 Correct 15 ms 17096 KB Output is correct
14 Correct 16 ms 17096 KB Output is correct
15 Correct 14 ms 17096 KB Output is correct
16 Correct 16 ms 17096 KB Output is correct
17 Correct 15 ms 17096 KB Output is correct
18 Correct 15 ms 17096 KB Output is correct
19 Correct 15 ms 17096 KB Output is correct
20 Correct 15 ms 17096 KB Output is correct
21 Correct 14 ms 17096 KB Output is correct
22 Correct 15 ms 17148 KB Output is correct
23 Correct 16 ms 17148 KB Output is correct
24 Correct 15 ms 17148 KB Output is correct
25 Correct 14 ms 17148 KB Output is correct
26 Correct 15 ms 17148 KB Output is correct
27 Correct 14 ms 17148 KB Output is correct
28 Correct 15 ms 17148 KB Output is correct
29 Correct 14 ms 17148 KB Output is correct
30 Correct 16 ms 17148 KB Output is correct
31 Correct 15 ms 17148 KB Output is correct
32 Correct 18 ms 17148 KB Output is correct
33 Correct 16 ms 17148 KB Output is correct
34 Correct 17 ms 17276 KB Output is correct
35 Correct 17 ms 17276 KB Output is correct
36 Correct 23 ms 17276 KB Output is correct
37 Correct 18 ms 17404 KB Output is correct
38 Correct 19 ms 17404 KB Output is correct
39 Correct 18 ms 17404 KB Output is correct
40 Correct 17 ms 17916 KB Output is correct
41 Correct 17 ms 17948 KB Output is correct
42 Correct 18 ms 17948 KB Output is correct
43 Correct 19 ms 17948 KB Output is correct
44 Correct 19 ms 17948 KB Output is correct
45 Correct 20 ms 18084 KB Output is correct
46 Correct 20 ms 18120 KB Output is correct
47 Correct 19 ms 18200 KB Output is correct
48 Correct 18 ms 18200 KB Output is correct
49 Correct 18 ms 18200 KB Output is correct
50 Correct 18 ms 18200 KB Output is correct
51 Correct 17 ms 18200 KB Output is correct
52 Correct 18 ms 18372 KB Output is correct
53 Correct 19 ms 18432 KB Output is correct
54 Correct 23 ms 18500 KB Output is correct
55 Correct 28 ms 19200 KB Output is correct
56 Correct 58 ms 22336 KB Output is correct
57 Correct 96 ms 25768 KB Output is correct
58 Correct 126 ms 29480 KB Output is correct
59 Correct 174 ms 33684 KB Output is correct
60 Correct 211 ms 38612 KB Output is correct
61 Correct 274 ms 43980 KB Output is correct
62 Correct 276 ms 48876 KB Output is correct
63 Correct 335 ms 55792 KB Output is correct
64 Correct 347 ms 61176 KB Output is correct
65 Correct 250 ms 98856 KB Output is correct
66 Correct 156 ms 103744 KB Output is correct
67 Correct 184 ms 103744 KB Output is correct
68 Correct 238 ms 103744 KB Output is correct
69 Correct 283 ms 103744 KB Output is correct
70 Correct 311 ms 104316 KB Output is correct
71 Correct 287 ms 108032 KB Output is correct
72 Correct 286 ms 112196 KB Output is correct
73 Correct 262 ms 113096 KB Output is correct
74 Correct 282 ms 117144 KB Output is correct
75 Correct 258 ms 119696 KB Output is correct
76 Correct 285 ms 123772 KB Output is correct
77 Correct 329 ms 126196 KB Output is correct
78 Correct 317 ms 129692 KB Output is correct
79 Correct 348 ms 132212 KB Output is correct