답안 #820170

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
820170 2023-08-10T22:32:02 Z PenguinsAreCute Fireworks (APIO16_fireworks) C++17
100 / 100
276 ms 73264 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define LL_MAX LONG_LONG_MAX
#define LL_MIN LONG_LONG_MIN
#define speed ios_base::sync_with_stdio(false); cin.tie(0)
#define stMx(a,b) a = max(a,b)
#define stMn(a,b) a = min(a,b)
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef set<int> si;
typedef vector<ii> vii;
typedef set<ii> sii;
#define REP(i, a, b) for(int i = a; i < b; i++)
#define HASTC 0
vii adj[300005];
priority_queue<int> slope[300005]; ii rgt[300005];
void dfs(int x, int p) {
    if(adj[x].size()) {
        for(auto i: adj[x]) {
            dfs(i.fi,i.se);
            if(slope[i.fi].size()>slope[x].size()) swap(slope[i.fi],slope[x]);
            while(slope[i.fi].size()) {
                slope[x].push(slope[i.fi].top());
                slope[i.fi].pop();
            }
            rgt[x].fi+=rgt[i.fi].fi; rgt[x].se+=rgt[i.fi].se;
        }
        while(rgt[x].fi>1) {
            rgt[x].fi--; assert(slope[x].size()); rgt[x].se+=slope[x].top();
            slope[x].pop();
        }
        int t, t2;
        t=slope[x].top(); slope[x].pop();
        t2=slope[x].top(); slope[x].pop();
        slope[x].push(t+p); slope[x].push(t2+p);
        rgt[x].se-=p;
    }
    else {
        slope[x].push(p);
        slope[x].push(p);
        rgt[x]=ii(1,-p);
    }
}
void solvetc(int idx) {
    int N, M, P, C; cin >> N >> M;
    REP(i,2,M+N+1) {
        cin>>P>>C;
        adj[P].pb(ii(i,C));
    }
    dfs(1,0);
    while(rgt[1].fi) {
        rgt[1].fi--; assert(slope[1].size()); rgt[1].se+=slope[1].top();
        slope[1].pop();
    }
    cout<<rgt[1].se;
}
int32_t main() {
    int tc;
    if(HASTC) cin>>tc;
    else tc=1;
    for(int i=0;i<tc;i++) solvetc(i);    
}
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 16724 KB Output is correct
2 Correct 8 ms 16744 KB Output is correct
3 Correct 8 ms 16724 KB Output is correct
4 Correct 8 ms 16724 KB Output is correct
5 Correct 8 ms 16724 KB Output is correct
6 Correct 9 ms 16724 KB Output is correct
7 Correct 8 ms 16724 KB Output is correct
8 Correct 9 ms 16736 KB Output is correct
9 Correct 8 ms 16724 KB Output is correct
10 Correct 9 ms 16724 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 16840 KB Output is correct
2 Correct 8 ms 16744 KB Output is correct
3 Correct 7 ms 16752 KB Output is correct
4 Correct 8 ms 16724 KB Output is correct
5 Correct 8 ms 16740 KB Output is correct
6 Correct 8 ms 16752 KB Output is correct
7 Correct 8 ms 16724 KB Output is correct
8 Correct 8 ms 16724 KB Output is correct
9 Correct 8 ms 16724 KB Output is correct
10 Correct 8 ms 16748 KB Output is correct
11 Correct 10 ms 16724 KB Output is correct
12 Correct 10 ms 16748 KB Output is correct
13 Correct 9 ms 16700 KB Output is correct
14 Correct 8 ms 16724 KB Output is correct
15 Correct 8 ms 16724 KB Output is correct
16 Correct 8 ms 16752 KB Output is correct
17 Correct 9 ms 16724 KB Output is correct
18 Correct 8 ms 16724 KB Output is correct
19 Correct 8 ms 16748 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 16724 KB Output is correct
2 Correct 8 ms 16744 KB Output is correct
3 Correct 8 ms 16724 KB Output is correct
4 Correct 8 ms 16724 KB Output is correct
5 Correct 8 ms 16724 KB Output is correct
6 Correct 9 ms 16724 KB Output is correct
7 Correct 8 ms 16724 KB Output is correct
8 Correct 9 ms 16736 KB Output is correct
9 Correct 8 ms 16724 KB Output is correct
10 Correct 9 ms 16724 KB Output is correct
11 Correct 11 ms 16840 KB Output is correct
12 Correct 8 ms 16744 KB Output is correct
13 Correct 7 ms 16752 KB Output is correct
14 Correct 8 ms 16724 KB Output is correct
15 Correct 8 ms 16740 KB Output is correct
16 Correct 8 ms 16752 KB Output is correct
17 Correct 8 ms 16724 KB Output is correct
18 Correct 8 ms 16724 KB Output is correct
19 Correct 8 ms 16724 KB Output is correct
20 Correct 8 ms 16748 KB Output is correct
21 Correct 10 ms 16724 KB Output is correct
22 Correct 10 ms 16748 KB Output is correct
23 Correct 9 ms 16700 KB Output is correct
24 Correct 8 ms 16724 KB Output is correct
25 Correct 8 ms 16724 KB Output is correct
26 Correct 8 ms 16752 KB Output is correct
27 Correct 9 ms 16724 KB Output is correct
28 Correct 8 ms 16724 KB Output is correct
29 Correct 8 ms 16748 KB Output is correct
30 Correct 8 ms 16724 KB Output is correct
31 Correct 8 ms 16808 KB Output is correct
32 Correct 8 ms 16812 KB Output is correct
33 Correct 10 ms 16984 KB Output is correct
34 Correct 11 ms 16988 KB Output is correct
35 Correct 10 ms 16980 KB Output is correct
36 Correct 10 ms 16980 KB Output is correct
37 Correct 11 ms 17108 KB Output is correct
38 Correct 11 ms 17100 KB Output is correct
39 Correct 12 ms 17108 KB Output is correct
40 Correct 11 ms 17620 KB Output is correct
41 Correct 11 ms 17620 KB Output is correct
42 Correct 12 ms 16980 KB Output is correct
43 Correct 11 ms 17364 KB Output is correct
44 Correct 12 ms 17236 KB Output is correct
45 Correct 12 ms 17236 KB Output is correct
46 Correct 11 ms 17236 KB Output is correct
47 Correct 12 ms 17272 KB Output is correct
48 Correct 10 ms 17108 KB Output is correct
49 Correct 11 ms 17144 KB Output is correct
50 Correct 11 ms 17108 KB Output is correct
51 Correct 10 ms 17012 KB Output is correct
52 Correct 11 ms 17108 KB Output is correct
53 Correct 12 ms 17236 KB Output is correct
54 Correct 11 ms 17144 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 16724 KB Output is correct
2 Correct 8 ms 16744 KB Output is correct
3 Correct 8 ms 16724 KB Output is correct
4 Correct 8 ms 16724 KB Output is correct
5 Correct 8 ms 16724 KB Output is correct
6 Correct 9 ms 16724 KB Output is correct
7 Correct 8 ms 16724 KB Output is correct
8 Correct 9 ms 16736 KB Output is correct
9 Correct 8 ms 16724 KB Output is correct
10 Correct 9 ms 16724 KB Output is correct
11 Correct 11 ms 16840 KB Output is correct
12 Correct 8 ms 16744 KB Output is correct
13 Correct 7 ms 16752 KB Output is correct
14 Correct 8 ms 16724 KB Output is correct
15 Correct 8 ms 16740 KB Output is correct
16 Correct 8 ms 16752 KB Output is correct
17 Correct 8 ms 16724 KB Output is correct
18 Correct 8 ms 16724 KB Output is correct
19 Correct 8 ms 16724 KB Output is correct
20 Correct 8 ms 16748 KB Output is correct
21 Correct 10 ms 16724 KB Output is correct
22 Correct 10 ms 16748 KB Output is correct
23 Correct 9 ms 16700 KB Output is correct
24 Correct 8 ms 16724 KB Output is correct
25 Correct 8 ms 16724 KB Output is correct
26 Correct 8 ms 16752 KB Output is correct
27 Correct 9 ms 16724 KB Output is correct
28 Correct 8 ms 16724 KB Output is correct
29 Correct 8 ms 16748 KB Output is correct
30 Correct 8 ms 16724 KB Output is correct
31 Correct 8 ms 16808 KB Output is correct
32 Correct 8 ms 16812 KB Output is correct
33 Correct 10 ms 16984 KB Output is correct
34 Correct 11 ms 16988 KB Output is correct
35 Correct 10 ms 16980 KB Output is correct
36 Correct 10 ms 16980 KB Output is correct
37 Correct 11 ms 17108 KB Output is correct
38 Correct 11 ms 17100 KB Output is correct
39 Correct 12 ms 17108 KB Output is correct
40 Correct 11 ms 17620 KB Output is correct
41 Correct 11 ms 17620 KB Output is correct
42 Correct 12 ms 16980 KB Output is correct
43 Correct 11 ms 17364 KB Output is correct
44 Correct 12 ms 17236 KB Output is correct
45 Correct 12 ms 17236 KB Output is correct
46 Correct 11 ms 17236 KB Output is correct
47 Correct 12 ms 17272 KB Output is correct
48 Correct 10 ms 17108 KB Output is correct
49 Correct 11 ms 17144 KB Output is correct
50 Correct 11 ms 17108 KB Output is correct
51 Correct 10 ms 17012 KB Output is correct
52 Correct 11 ms 17108 KB Output is correct
53 Correct 12 ms 17236 KB Output is correct
54 Correct 11 ms 17144 KB Output is correct
55 Correct 21 ms 17760 KB Output is correct
56 Correct 44 ms 20940 KB Output is correct
57 Correct 76 ms 23844 KB Output is correct
58 Correct 100 ms 25776 KB Output is correct
59 Correct 121 ms 28784 KB Output is correct
60 Correct 161 ms 31896 KB Output is correct
61 Correct 206 ms 34328 KB Output is correct
62 Correct 220 ms 36068 KB Output is correct
63 Correct 269 ms 39628 KB Output is correct
64 Correct 276 ms 40732 KB Output is correct
65 Correct 193 ms 73200 KB Output is correct
66 Correct 192 ms 73264 KB Output is correct
67 Correct 191 ms 35716 KB Output is correct
68 Correct 230 ms 57816 KB Output is correct
69 Correct 249 ms 55252 KB Output is correct
70 Correct 275 ms 55328 KB Output is correct
71 Correct 230 ms 53236 KB Output is correct
72 Correct 230 ms 53288 KB Output is correct
73 Correct 210 ms 48968 KB Output is correct
74 Correct 205 ms 49204 KB Output is correct
75 Correct 204 ms 47444 KB Output is correct
76 Correct 211 ms 47476 KB Output is correct
77 Correct 232 ms 46648 KB Output is correct
78 Correct 244 ms 44760 KB Output is correct
79 Correct 210 ms 46528 KB Output is correct