답안 #108388

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
108388 2019-04-29T03:49:48 Z kuroni Fireworks (APIO16_fireworks) C++17
100 / 100
303 ms 44096 KB
#include <iostream>
#include <cstdio>
#include <queue>
using namespace std;

const int MX = 300005;

int n, m, p[MX], c[MX];

struct TSlope
{
    priority_queue<long long> pq;
    long long a, b;

    TSlope()
    {
        while (!pq.empty())
            pq.pop();
        a = b = 0;
    }

    void pop()
    {
        a--;
        b += pq.top();
        pq.pop();
    }
} sl[MX];

int main()
{
    scanf("%d%d", &n, &m);
    for (int i = 2; i <= n + m; i++)
        scanf("%d%d", p + i, c + i);
    for (int i = n + m; i >= 2; i--)
    {
        TSlope &cur = sl[i], &par = sl[p[i]];
        if (i > n)
        {
            cur.pq.push(c[i]); cur.pq.push(c[i]);
            cur.a = 1; cur.b = -c[i];
        }
        else
        {
            while (cur.a > 1)
                cur.pop();
            long long u = cur.pq.top(); cur.pq.pop();
            long long v = cur.pq.top(); cur.pq.pop();
            cur.pq.push(u + c[i]); cur.pq.push(v + c[i]);
            cur.b -= c[i];
        }
        if (par.pq.size() < cur.pq.size())
            swap(par, cur);
        while (!cur.pq.empty())
        {
            par.pq.push(cur.pq.top());
            cur.pq.pop();
        }
        par.a += cur.a; par.b += cur.b;
    }
    TSlope &cur = sl[1];
    while (cur.a > 0)
        cur.pop();
    printf("%lld\n", cur.a * cur.pq.top() + cur.b);
}

Compilation message

fireworks.cpp: In function 'int main()':
fireworks.cpp:32:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d", &n, &m);
     ~~~~~^~~~~~~~~~~~~~~~
fireworks.cpp:34:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d", p + i, c + i);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 14464 KB Output is correct
2 Correct 15 ms 14464 KB Output is correct
3 Correct 14 ms 14464 KB Output is correct
4 Correct 15 ms 14464 KB Output is correct
5 Correct 15 ms 14464 KB Output is correct
6 Correct 16 ms 14464 KB Output is correct
7 Correct 16 ms 14436 KB Output is correct
8 Correct 17 ms 14464 KB Output is correct
9 Correct 15 ms 14464 KB Output is correct
10 Correct 15 ms 14464 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 14464 KB Output is correct
2 Correct 23 ms 14464 KB Output is correct
3 Correct 15 ms 14464 KB Output is correct
4 Correct 16 ms 14464 KB Output is correct
5 Correct 16 ms 14464 KB Output is correct
6 Correct 15 ms 14464 KB Output is correct
7 Correct 15 ms 14492 KB Output is correct
8 Correct 55 ms 14456 KB Output is correct
9 Correct 15 ms 14464 KB Output is correct
10 Correct 17 ms 14464 KB Output is correct
11 Correct 15 ms 14464 KB Output is correct
12 Correct 16 ms 14464 KB Output is correct
13 Correct 18 ms 14464 KB Output is correct
14 Correct 15 ms 14456 KB Output is correct
15 Correct 16 ms 14464 KB Output is correct
16 Correct 16 ms 14464 KB Output is correct
17 Correct 15 ms 14464 KB Output is correct
18 Correct 16 ms 14464 KB Output is correct
19 Correct 17 ms 14464 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 14464 KB Output is correct
2 Correct 15 ms 14464 KB Output is correct
3 Correct 14 ms 14464 KB Output is correct
4 Correct 15 ms 14464 KB Output is correct
5 Correct 15 ms 14464 KB Output is correct
6 Correct 16 ms 14464 KB Output is correct
7 Correct 16 ms 14436 KB Output is correct
8 Correct 17 ms 14464 KB Output is correct
9 Correct 15 ms 14464 KB Output is correct
10 Correct 15 ms 14464 KB Output is correct
11 Correct 16 ms 14464 KB Output is correct
12 Correct 23 ms 14464 KB Output is correct
13 Correct 15 ms 14464 KB Output is correct
14 Correct 16 ms 14464 KB Output is correct
15 Correct 16 ms 14464 KB Output is correct
16 Correct 15 ms 14464 KB Output is correct
17 Correct 15 ms 14492 KB Output is correct
18 Correct 55 ms 14456 KB Output is correct
19 Correct 15 ms 14464 KB Output is correct
20 Correct 17 ms 14464 KB Output is correct
21 Correct 15 ms 14464 KB Output is correct
22 Correct 16 ms 14464 KB Output is correct
23 Correct 18 ms 14464 KB Output is correct
24 Correct 15 ms 14456 KB Output is correct
25 Correct 16 ms 14464 KB Output is correct
26 Correct 16 ms 14464 KB Output is correct
27 Correct 15 ms 14464 KB Output is correct
28 Correct 16 ms 14464 KB Output is correct
29 Correct 17 ms 14464 KB Output is correct
30 Correct 16 ms 14464 KB Output is correct
31 Correct 15 ms 14464 KB Output is correct
32 Correct 18 ms 14576 KB Output is correct
33 Correct 20 ms 14592 KB Output is correct
34 Correct 16 ms 14592 KB Output is correct
35 Correct 17 ms 14592 KB Output is correct
36 Correct 20 ms 14720 KB Output is correct
37 Correct 19 ms 14720 KB Output is correct
38 Correct 29 ms 14732 KB Output is correct
39 Correct 20 ms 14720 KB Output is correct
40 Correct 17 ms 14592 KB Output is correct
41 Correct 17 ms 14564 KB Output is correct
42 Correct 17 ms 14592 KB Output is correct
43 Correct 19 ms 14720 KB Output is correct
44 Correct 22 ms 14720 KB Output is correct
45 Correct 20 ms 14720 KB Output is correct
46 Correct 19 ms 14848 KB Output is correct
47 Correct 18 ms 14976 KB Output is correct
48 Correct 18 ms 14848 KB Output is correct
49 Correct 20 ms 14848 KB Output is correct
50 Correct 17 ms 14712 KB Output is correct
51 Correct 20 ms 14720 KB Output is correct
52 Correct 19 ms 14848 KB Output is correct
53 Correct 20 ms 14876 KB Output is correct
54 Correct 22 ms 14768 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 14464 KB Output is correct
2 Correct 15 ms 14464 KB Output is correct
3 Correct 14 ms 14464 KB Output is correct
4 Correct 15 ms 14464 KB Output is correct
5 Correct 15 ms 14464 KB Output is correct
6 Correct 16 ms 14464 KB Output is correct
7 Correct 16 ms 14436 KB Output is correct
8 Correct 17 ms 14464 KB Output is correct
9 Correct 15 ms 14464 KB Output is correct
10 Correct 15 ms 14464 KB Output is correct
11 Correct 16 ms 14464 KB Output is correct
12 Correct 23 ms 14464 KB Output is correct
13 Correct 15 ms 14464 KB Output is correct
14 Correct 16 ms 14464 KB Output is correct
15 Correct 16 ms 14464 KB Output is correct
16 Correct 15 ms 14464 KB Output is correct
17 Correct 15 ms 14492 KB Output is correct
18 Correct 55 ms 14456 KB Output is correct
19 Correct 15 ms 14464 KB Output is correct
20 Correct 17 ms 14464 KB Output is correct
21 Correct 15 ms 14464 KB Output is correct
22 Correct 16 ms 14464 KB Output is correct
23 Correct 18 ms 14464 KB Output is correct
24 Correct 15 ms 14456 KB Output is correct
25 Correct 16 ms 14464 KB Output is correct
26 Correct 16 ms 14464 KB Output is correct
27 Correct 15 ms 14464 KB Output is correct
28 Correct 16 ms 14464 KB Output is correct
29 Correct 17 ms 14464 KB Output is correct
30 Correct 16 ms 14464 KB Output is correct
31 Correct 15 ms 14464 KB Output is correct
32 Correct 18 ms 14576 KB Output is correct
33 Correct 20 ms 14592 KB Output is correct
34 Correct 16 ms 14592 KB Output is correct
35 Correct 17 ms 14592 KB Output is correct
36 Correct 20 ms 14720 KB Output is correct
37 Correct 19 ms 14720 KB Output is correct
38 Correct 29 ms 14732 KB Output is correct
39 Correct 20 ms 14720 KB Output is correct
40 Correct 17 ms 14592 KB Output is correct
41 Correct 17 ms 14564 KB Output is correct
42 Correct 17 ms 14592 KB Output is correct
43 Correct 19 ms 14720 KB Output is correct
44 Correct 22 ms 14720 KB Output is correct
45 Correct 20 ms 14720 KB Output is correct
46 Correct 19 ms 14848 KB Output is correct
47 Correct 18 ms 14976 KB Output is correct
48 Correct 18 ms 14848 KB Output is correct
49 Correct 20 ms 14848 KB Output is correct
50 Correct 17 ms 14712 KB Output is correct
51 Correct 20 ms 14720 KB Output is correct
52 Correct 19 ms 14848 KB Output is correct
53 Correct 20 ms 14876 KB Output is correct
54 Correct 22 ms 14768 KB Output is correct
55 Correct 25 ms 15232 KB Output is correct
56 Correct 41 ms 17452 KB Output is correct
57 Correct 65 ms 19448 KB Output is correct
58 Correct 88 ms 21108 KB Output is correct
59 Correct 103 ms 23024 KB Output is correct
60 Correct 160 ms 25076 KB Output is correct
61 Correct 156 ms 26992 KB Output is correct
62 Correct 169 ms 28140 KB Output is correct
63 Correct 214 ms 30668 KB Output is correct
64 Correct 211 ms 31472 KB Output is correct
65 Correct 92 ms 21624 KB Output is correct
66 Correct 126 ms 21632 KB Output is correct
67 Correct 147 ms 21624 KB Output is correct
68 Correct 167 ms 28532 KB Output is correct
69 Correct 192 ms 29012 KB Output is correct
70 Correct 179 ms 29044 KB Output is correct
71 Correct 229 ms 44096 KB Output is correct
72 Correct 272 ms 44004 KB Output is correct
73 Correct 242 ms 40420 KB Output is correct
74 Correct 249 ms 40948 KB Output is correct
75 Correct 200 ms 39400 KB Output is correct
76 Correct 303 ms 39268 KB Output is correct
77 Correct 228 ms 38884 KB Output is correct
78 Correct 213 ms 38372 KB Output is correct
79 Correct 251 ms 36700 KB Output is correct