답안 #685053

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
685053 2023-01-23T08:04:21 Z minhnhatnoe Fireworks (APIO16_fireworks) C++14
100 / 100
174 ms 63624 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
struct slope{
    priority_queue<ll> s;
    ll a, b;
    int size(){
        return s.size();
    }
};
vector<vector<int>> g;
vector<slope> dp;
vector<int> c;
void merge_pq(priority_queue<ll> &a, priority_queue<ll> &&b){
    while (b.size()){
        a.push(b.top());
        b.pop();
    }
}
slope merge(vector<slope> &&a, ll c){
    for (int i=1; i<a.size(); i++){
        if (a[i].size() > a[0].size()) swap(a[i], a[0]);
    }
    slope r(move(a[0]));
    for (int i=1; i<a.size(); i++){
        r.a += a[i].a;
        r.b += a[i].b;
        merge_pq(r.s, move(a[i].s));
    }
    while (r.a > 1){
        r.a--;
        r.b += r.s.top();
        r.s.pop();
    }
    ll x = LLONG_MIN;
    if (r.s.size() && r.a >= 0){
        x = r.s.top();
        r.s.pop();
    }
    ll y = LLONG_MIN;
    if (r.s.size() && r.a >= 1){
        y = r.s.top();
        r.s.pop();
    }
    if (x != LLONG_MIN) r.s.push(x + c);
    if (y != LLONG_MIN) r.s.push(y + c);
    r.b -= c;
    return r;
}
signed main(){
    cin.tie(0)->sync_with_stdio(0);
    int n, m; cin >> n >> m;
    g.resize(n+m);
    c.resize(n+m);
    dp.resize(n+m);
    for (int i=1; i<n; i++){
        int p; cin >> p >> c[i];
        g[p-1].push_back(i);
    }
    for (int i=n; i<n+m; i++){
        int p; cin >> p >> c[i];
        g[p-1].push_back(i);
        dp[i].a = 1;
        dp[i].b = -c[i];
        dp[i].s.push(c[i]), dp[i].s.push(c[i]);
    }
    for (int i=n-1; i>=0; i--){
        vector<slope> ch;
        for (int u: g[i]){
            ch.emplace_back(move(dp[u]));
        }
        dp[i] = merge(move(ch), c[i]);
    }
    slope r(move(dp[0]));
    if (r.a == 1){
        cout << r.b + r.s.top() << "\n";
    }
    else{
        cout << r.b << "\n";
    }
}

Compilation message

fireworks.cpp: In function 'slope merge(std::vector<slope>&&, ll)':
fireworks.cpp:21:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<slope>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   21 |     for (int i=1; i<a.size(); i++){
      |                   ~^~~~~~~~~
fireworks.cpp:25:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<slope>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   25 |     for (int i=1; i<a.size(); i++){
      |                   ~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 1 ms 320 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 320 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 340 KB Output is correct
7 Correct 1 ms 316 KB Output is correct
8 Correct 0 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 352 KB Output is correct
14 Correct 0 ms 352 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 328 KB Output is correct
19 Correct 1 ms 352 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 1 ms 320 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 320 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 1 ms 316 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 352 KB Output is correct
24 Correct 0 ms 352 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 328 KB Output is correct
29 Correct 1 ms 352 KB Output is correct
30 Correct 1 ms 352 KB Output is correct
31 Correct 1 ms 480 KB Output is correct
32 Correct 1 ms 468 KB Output is correct
33 Correct 1 ms 596 KB Output is correct
34 Correct 2 ms 724 KB Output is correct
35 Correct 2 ms 732 KB Output is correct
36 Correct 2 ms 856 KB Output is correct
37 Correct 3 ms 992 KB Output is correct
38 Correct 3 ms 992 KB Output is correct
39 Correct 3 ms 972 KB Output is correct
40 Correct 2 ms 864 KB Output is correct
41 Correct 2 ms 864 KB Output is correct
42 Correct 2 ms 864 KB Output is correct
43 Correct 3 ms 864 KB Output is correct
44 Correct 3 ms 992 KB Output is correct
45 Correct 4 ms 992 KB Output is correct
46 Correct 3 ms 992 KB Output is correct
47 Correct 3 ms 992 KB Output is correct
48 Correct 3 ms 992 KB Output is correct
49 Correct 3 ms 1116 KB Output is correct
50 Correct 2 ms 1120 KB Output is correct
51 Correct 2 ms 1120 KB Output is correct
52 Correct 2 ms 1120 KB Output is correct
53 Correct 3 ms 1036 KB Output is correct
54 Correct 3 ms 1440 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 1 ms 320 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 320 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 0 ms 340 KB Output is correct
17 Correct 1 ms 316 KB Output is correct
18 Correct 0 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 352 KB Output is correct
24 Correct 0 ms 352 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 328 KB Output is correct
29 Correct 1 ms 352 KB Output is correct
30 Correct 1 ms 352 KB Output is correct
31 Correct 1 ms 480 KB Output is correct
32 Correct 1 ms 468 KB Output is correct
33 Correct 1 ms 596 KB Output is correct
34 Correct 2 ms 724 KB Output is correct
35 Correct 2 ms 732 KB Output is correct
36 Correct 2 ms 856 KB Output is correct
37 Correct 3 ms 992 KB Output is correct
38 Correct 3 ms 992 KB Output is correct
39 Correct 3 ms 972 KB Output is correct
40 Correct 2 ms 864 KB Output is correct
41 Correct 2 ms 864 KB Output is correct
42 Correct 2 ms 864 KB Output is correct
43 Correct 3 ms 864 KB Output is correct
44 Correct 3 ms 992 KB Output is correct
45 Correct 4 ms 992 KB Output is correct
46 Correct 3 ms 992 KB Output is correct
47 Correct 3 ms 992 KB Output is correct
48 Correct 3 ms 992 KB Output is correct
49 Correct 3 ms 1116 KB Output is correct
50 Correct 2 ms 1120 KB Output is correct
51 Correct 2 ms 1120 KB Output is correct
52 Correct 2 ms 1120 KB Output is correct
53 Correct 3 ms 1036 KB Output is correct
54 Correct 3 ms 1440 KB Output is correct
55 Correct 6 ms 2120 KB Output is correct
56 Correct 25 ms 7132 KB Output is correct
57 Correct 45 ms 12096 KB Output is correct
58 Correct 63 ms 15428 KB Output is correct
59 Correct 83 ms 20232 KB Output is correct
60 Correct 102 ms 24896 KB Output is correct
61 Correct 122 ms 28328 KB Output is correct
62 Correct 139 ms 31036 KB Output is correct
63 Correct 165 ms 37236 KB Output is correct
64 Correct 174 ms 39364 KB Output is correct
65 Correct 96 ms 36916 KB Output is correct
66 Correct 95 ms 36940 KB Output is correct
67 Correct 98 ms 36916 KB Output is correct
68 Correct 146 ms 36664 KB Output is correct
69 Correct 165 ms 38976 KB Output is correct
70 Correct 165 ms 38972 KB Output is correct
71 Correct 166 ms 44556 KB Output is correct
72 Correct 166 ms 44744 KB Output is correct
73 Correct 149 ms 41880 KB Output is correct
74 Correct 151 ms 42076 KB Output is correct
75 Correct 146 ms 41856 KB Output is correct
76 Correct 145 ms 41936 KB Output is correct
77 Correct 158 ms 47892 KB Output is correct
78 Correct 160 ms 48604 KB Output is correct
79 Correct 155 ms 63624 KB Output is correct