답안 #671075

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
671075 2022-12-11T22:31:42 Z AdamGS Fireworks (APIO16_fireworks) C++17
100 / 100
220 ms 63880 KB
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(a, b) for(int a = 0; a < (b); ++a)
#define st first
#define nd second
#define pb push_back
#define all(a) a.begin(), a.end()
const int LIM=3e5+7;
vector<pair<int,ll>>V[LIM];
ll n, m, ans;
void DFS2(int x, ll k, priority_queue<ll>&q) {
        ans+=k;
        if(x>=n) {
                q.push(0);
                q.push(k);
                q.push(k);
                return;
        }
        DFS2(V[x][0].st, V[x][0].nd, q);
        for(int i=1; i<V[x].size(); ++i) {
                priority_queue<ll>p;
                DFS2(V[x][i].st, V[x][i].nd, p);
                if(p.size()>q.size()) swap(p, q);
                while(!p.empty()) {
                        q.push(p.top());
                        p.pop();
                }
        }
        rep(i, V[x].size()-1) q.pop();
        ll a=q.top(); q.pop();
        ll b=q.top(); q.pop();
        q.push(a+k); q.push(b+k);
}
int main() {
        ios_base::sync_with_stdio(0); cin.tie(0);
        cin >> n >> m;
        rep(i, n+m-1) {
                ll a, b;
                cin >> a >> b; --a;
                V[a].pb({i+1, b});
        }
        priority_queue<ll>Q;
        DFS2(0, 0, Q);
        Q.pop();
        vector<ll>P;
        while(!Q.empty()) {
                P.pb(Q.top());
                Q.pop();
        }
        for(ll i=P.size()-1; i; --i) ans-=i*(P[i-1]-P[i]);
        cout << ans << '\n';
}

Compilation message

fireworks.cpp: In function 'void DFS2(int, ll, std::priority_queue<long long int>&)':
fireworks.cpp:22:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   22 |         for(int i=1; i<V[x].size(); ++i) {
      |                      ~^~~~~~~~~~~~
fireworks.cpp:5:36: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    5 | #define rep(a, b) for(int a = 0; a < (b); ++a)
      |                                    ^
fireworks.cpp:31:9: note: in expansion of macro 'rep'
   31 |         rep(i, V[x].size()-1) q.pop();
      |         ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 7252 KB Output is correct
2 Correct 4 ms 7368 KB Output is correct
3 Correct 6 ms 7320 KB Output is correct
4 Correct 4 ms 7380 KB Output is correct
5 Correct 4 ms 7364 KB Output is correct
6 Correct 4 ms 7252 KB Output is correct
7 Correct 4 ms 7380 KB Output is correct
8 Correct 4 ms 7252 KB Output is correct
9 Correct 4 ms 7364 KB Output is correct
10 Correct 5 ms 7368 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 7252 KB Output is correct
2 Correct 4 ms 7368 KB Output is correct
3 Correct 4 ms 7368 KB Output is correct
4 Correct 4 ms 7368 KB Output is correct
5 Correct 4 ms 7368 KB Output is correct
6 Correct 4 ms 7252 KB Output is correct
7 Correct 4 ms 7364 KB Output is correct
8 Correct 4 ms 7364 KB Output is correct
9 Correct 4 ms 7252 KB Output is correct
10 Correct 4 ms 7252 KB Output is correct
11 Correct 5 ms 7380 KB Output is correct
12 Correct 4 ms 7380 KB Output is correct
13 Correct 4 ms 7380 KB Output is correct
14 Correct 4 ms 7380 KB Output is correct
15 Correct 4 ms 7380 KB Output is correct
16 Correct 5 ms 7292 KB Output is correct
17 Correct 4 ms 7380 KB Output is correct
18 Correct 4 ms 7380 KB Output is correct
19 Correct 4 ms 7284 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 7252 KB Output is correct
2 Correct 4 ms 7368 KB Output is correct
3 Correct 6 ms 7320 KB Output is correct
4 Correct 4 ms 7380 KB Output is correct
5 Correct 4 ms 7364 KB Output is correct
6 Correct 4 ms 7252 KB Output is correct
7 Correct 4 ms 7380 KB Output is correct
8 Correct 4 ms 7252 KB Output is correct
9 Correct 4 ms 7364 KB Output is correct
10 Correct 5 ms 7368 KB Output is correct
11 Correct 4 ms 7252 KB Output is correct
12 Correct 4 ms 7368 KB Output is correct
13 Correct 4 ms 7368 KB Output is correct
14 Correct 4 ms 7368 KB Output is correct
15 Correct 4 ms 7368 KB Output is correct
16 Correct 4 ms 7252 KB Output is correct
17 Correct 4 ms 7364 KB Output is correct
18 Correct 4 ms 7364 KB Output is correct
19 Correct 4 ms 7252 KB Output is correct
20 Correct 4 ms 7252 KB Output is correct
21 Correct 5 ms 7380 KB Output is correct
22 Correct 4 ms 7380 KB Output is correct
23 Correct 4 ms 7380 KB Output is correct
24 Correct 4 ms 7380 KB Output is correct
25 Correct 4 ms 7380 KB Output is correct
26 Correct 5 ms 7292 KB Output is correct
27 Correct 4 ms 7380 KB Output is correct
28 Correct 4 ms 7380 KB Output is correct
29 Correct 4 ms 7284 KB Output is correct
30 Correct 4 ms 7368 KB Output is correct
31 Correct 4 ms 7380 KB Output is correct
32 Correct 5 ms 7444 KB Output is correct
33 Correct 6 ms 7508 KB Output is correct
34 Correct 5 ms 7504 KB Output is correct
35 Correct 5 ms 7504 KB Output is correct
36 Correct 6 ms 7636 KB Output is correct
37 Correct 6 ms 7636 KB Output is correct
38 Correct 6 ms 7592 KB Output is correct
39 Correct 6 ms 7640 KB Output is correct
40 Correct 6 ms 8276 KB Output is correct
41 Correct 6 ms 8276 KB Output is correct
42 Correct 6 ms 7508 KB Output is correct
43 Correct 6 ms 8020 KB Output is correct
44 Correct 6 ms 8020 KB Output is correct
45 Correct 6 ms 8020 KB Output is correct
46 Correct 7 ms 7840 KB Output is correct
47 Correct 7 ms 7752 KB Output is correct
48 Correct 6 ms 7780 KB Output is correct
49 Correct 7 ms 7764 KB Output is correct
50 Correct 7 ms 7764 KB Output is correct
51 Correct 6 ms 7764 KB Output is correct
52 Correct 6 ms 7716 KB Output is correct
53 Correct 7 ms 7836 KB Output is correct
54 Correct 7 ms 7892 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 7252 KB Output is correct
2 Correct 4 ms 7368 KB Output is correct
3 Correct 6 ms 7320 KB Output is correct
4 Correct 4 ms 7380 KB Output is correct
5 Correct 4 ms 7364 KB Output is correct
6 Correct 4 ms 7252 KB Output is correct
7 Correct 4 ms 7380 KB Output is correct
8 Correct 4 ms 7252 KB Output is correct
9 Correct 4 ms 7364 KB Output is correct
10 Correct 5 ms 7368 KB Output is correct
11 Correct 4 ms 7252 KB Output is correct
12 Correct 4 ms 7368 KB Output is correct
13 Correct 4 ms 7368 KB Output is correct
14 Correct 4 ms 7368 KB Output is correct
15 Correct 4 ms 7368 KB Output is correct
16 Correct 4 ms 7252 KB Output is correct
17 Correct 4 ms 7364 KB Output is correct
18 Correct 4 ms 7364 KB Output is correct
19 Correct 4 ms 7252 KB Output is correct
20 Correct 4 ms 7252 KB Output is correct
21 Correct 5 ms 7380 KB Output is correct
22 Correct 4 ms 7380 KB Output is correct
23 Correct 4 ms 7380 KB Output is correct
24 Correct 4 ms 7380 KB Output is correct
25 Correct 4 ms 7380 KB Output is correct
26 Correct 5 ms 7292 KB Output is correct
27 Correct 4 ms 7380 KB Output is correct
28 Correct 4 ms 7380 KB Output is correct
29 Correct 4 ms 7284 KB Output is correct
30 Correct 4 ms 7368 KB Output is correct
31 Correct 4 ms 7380 KB Output is correct
32 Correct 5 ms 7444 KB Output is correct
33 Correct 6 ms 7508 KB Output is correct
34 Correct 5 ms 7504 KB Output is correct
35 Correct 5 ms 7504 KB Output is correct
36 Correct 6 ms 7636 KB Output is correct
37 Correct 6 ms 7636 KB Output is correct
38 Correct 6 ms 7592 KB Output is correct
39 Correct 6 ms 7640 KB Output is correct
40 Correct 6 ms 8276 KB Output is correct
41 Correct 6 ms 8276 KB Output is correct
42 Correct 6 ms 7508 KB Output is correct
43 Correct 6 ms 8020 KB Output is correct
44 Correct 6 ms 8020 KB Output is correct
45 Correct 6 ms 8020 KB Output is correct
46 Correct 7 ms 7840 KB Output is correct
47 Correct 7 ms 7752 KB Output is correct
48 Correct 6 ms 7780 KB Output is correct
49 Correct 7 ms 7764 KB Output is correct
50 Correct 7 ms 7764 KB Output is correct
51 Correct 6 ms 7764 KB Output is correct
52 Correct 6 ms 7716 KB Output is correct
53 Correct 7 ms 7836 KB Output is correct
54 Correct 7 ms 7892 KB Output is correct
55 Correct 11 ms 8152 KB Output is correct
56 Correct 29 ms 10060 KB Output is correct
57 Correct 47 ms 11124 KB Output is correct
58 Correct 61 ms 12660 KB Output is correct
59 Correct 84 ms 13864 KB Output is correct
60 Correct 117 ms 15652 KB Output is correct
61 Correct 131 ms 17440 KB Output is correct
62 Correct 147 ms 18144 KB Output is correct
63 Correct 170 ms 19464 KB Output is correct
64 Correct 181 ms 19972 KB Output is correct
65 Correct 99 ms 63880 KB Output is correct
66 Correct 100 ms 63880 KB Output is correct
67 Correct 84 ms 17136 KB Output is correct
68 Correct 166 ms 46588 KB Output is correct
69 Correct 184 ms 43572 KB Output is correct
70 Correct 193 ms 43472 KB Output is correct
71 Correct 220 ms 31428 KB Output is correct
72 Correct 211 ms 31548 KB Output is correct
73 Correct 201 ms 30700 KB Output is correct
74 Correct 197 ms 30832 KB Output is correct
75 Correct 191 ms 29948 KB Output is correct
76 Correct 195 ms 30060 KB Output is correct
77 Correct 196 ms 30076 KB Output is correct
78 Correct 202 ms 29928 KB Output is correct
79 Correct 197 ms 31696 KB Output is correct