Submission #284992

# Submission time Handle Problem Language Result Execution time Memory
284992 2020-08-28T08:45:28 Z Kastanda Fireworks (APIO16_fireworks) C++11
100 / 100
281 ms 52608 KB
// M
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 300005;
int n, m, P[N], C[N];
vector < int > Ch[N];
priority_queue < ll > PQ[N];
int main()
{
        scanf("%d%d", &n, &m);
        for (int i = 2; i <= n + m; i ++)
                scanf("%d%d", &P[i], &C[i]), Ch[P[i]].push_back(i);
        for (int v = n + m; v; v --)
        {
                if (!Ch[v].size())
                {
                        PQ[v].push(C[v]);
                        PQ[v].push(C[v]);
                        continue;
                }
                for (int u : Ch[v])
                {
                        if (PQ[v].size() < PQ[u].size())
                                PQ[v].swap(PQ[u]);
                        while (PQ[u].size())
                                PQ[v].push(PQ[u].top()), PQ[u].pop();
                }
                for (int i = 0; i < (int)Ch[v].size() - 1; i ++)
                        PQ[v].pop(); // Note that now there are extra positive slopes other than +1.
                // Only the intervals with slope equal to 0 or 1 shift C[v] units to the right.
                ll slope1 = PQ[v].top(); PQ[v].pop();
                ll slope0 = PQ[v].top(); PQ[v].pop();
                PQ[v].push(slope0 + C[v]);
                PQ[v].push(slope1 + C[v]);
        }
        PQ[1].pop(); // Getting rid of the interval with slope +1.
        ll SM = 0; // SM is the value of F(0).
        for (int v = 1; v <= n + m; v ++)
                SM += C[v];
        vector < ll > V;
        while (PQ[1].size())
                V.push_back(PQ[1].top()), PQ[1].pop();
        V.push_back(0);
        reverse(V.begin(), V.end());
        for (int i = 1; i < (int)V.size(); i ++)
                SM -= (V[i] - V[i - 1]) * ((int)V.size() - i);
        return !printf("%lld\n", SM);
}

Compilation message

fireworks.cpp: In function 'int main()':
fireworks.cpp:11:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   11 |         scanf("%d%d", &n, &m);
      |         ~~~~~^~~~~~~~~~~~~~~~
fireworks.cpp:13:22: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   13 |                 scanf("%d%d", &P[i], &C[i]), Ch[P[i]].push_back(i);
      |                 ~~~~~^~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 11 ms 16768 KB Output is correct
2 Correct 11 ms 16768 KB Output is correct
3 Correct 12 ms 16768 KB Output is correct
4 Correct 12 ms 16896 KB Output is correct
5 Correct 12 ms 16768 KB Output is correct
6 Correct 13 ms 16768 KB Output is correct
7 Correct 13 ms 16768 KB Output is correct
8 Correct 13 ms 16768 KB Output is correct
9 Correct 13 ms 16768 KB Output is correct
10 Correct 12 ms 16768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 16768 KB Output is correct
2 Correct 12 ms 16768 KB Output is correct
3 Correct 13 ms 16788 KB Output is correct
4 Correct 13 ms 16768 KB Output is correct
5 Correct 13 ms 16768 KB Output is correct
6 Correct 13 ms 16768 KB Output is correct
7 Correct 13 ms 16768 KB Output is correct
8 Correct 13 ms 16768 KB Output is correct
9 Correct 12 ms 16840 KB Output is correct
10 Correct 12 ms 16768 KB Output is correct
11 Correct 13 ms 16768 KB Output is correct
12 Correct 12 ms 16768 KB Output is correct
13 Correct 12 ms 16768 KB Output is correct
14 Correct 13 ms 16768 KB Output is correct
15 Correct 12 ms 16768 KB Output is correct
16 Correct 13 ms 16768 KB Output is correct
17 Correct 12 ms 16768 KB Output is correct
18 Correct 12 ms 16768 KB Output is correct
19 Correct 12 ms 16768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 16768 KB Output is correct
2 Correct 11 ms 16768 KB Output is correct
3 Correct 12 ms 16768 KB Output is correct
4 Correct 12 ms 16896 KB Output is correct
5 Correct 12 ms 16768 KB Output is correct
6 Correct 13 ms 16768 KB Output is correct
7 Correct 13 ms 16768 KB Output is correct
8 Correct 13 ms 16768 KB Output is correct
9 Correct 13 ms 16768 KB Output is correct
10 Correct 12 ms 16768 KB Output is correct
11 Correct 12 ms 16768 KB Output is correct
12 Correct 12 ms 16768 KB Output is correct
13 Correct 13 ms 16788 KB Output is correct
14 Correct 13 ms 16768 KB Output is correct
15 Correct 13 ms 16768 KB Output is correct
16 Correct 13 ms 16768 KB Output is correct
17 Correct 13 ms 16768 KB Output is correct
18 Correct 13 ms 16768 KB Output is correct
19 Correct 12 ms 16840 KB Output is correct
20 Correct 12 ms 16768 KB Output is correct
21 Correct 13 ms 16768 KB Output is correct
22 Correct 12 ms 16768 KB Output is correct
23 Correct 12 ms 16768 KB Output is correct
24 Correct 13 ms 16768 KB Output is correct
25 Correct 12 ms 16768 KB Output is correct
26 Correct 13 ms 16768 KB Output is correct
27 Correct 12 ms 16768 KB Output is correct
28 Correct 12 ms 16768 KB Output is correct
29 Correct 12 ms 16768 KB Output is correct
30 Correct 12 ms 16852 KB Output is correct
31 Correct 13 ms 16896 KB Output is correct
32 Correct 13 ms 17024 KB Output is correct
33 Correct 16 ms 16896 KB Output is correct
34 Correct 13 ms 17024 KB Output is correct
35 Correct 14 ms 17024 KB Output is correct
36 Correct 14 ms 17024 KB Output is correct
37 Correct 18 ms 17152 KB Output is correct
38 Correct 16 ms 17152 KB Output is correct
39 Correct 14 ms 17152 KB Output is correct
40 Correct 13 ms 17024 KB Output is correct
41 Correct 16 ms 17024 KB Output is correct
42 Correct 14 ms 17024 KB Output is correct
43 Correct 15 ms 17152 KB Output is correct
44 Correct 14 ms 17152 KB Output is correct
45 Correct 15 ms 17152 KB Output is correct
46 Correct 15 ms 17280 KB Output is correct
47 Correct 15 ms 17280 KB Output is correct
48 Correct 18 ms 17152 KB Output is correct
49 Correct 15 ms 17280 KB Output is correct
50 Correct 14 ms 17152 KB Output is correct
51 Correct 14 ms 17152 KB Output is correct
52 Correct 14 ms 17152 KB Output is correct
53 Correct 15 ms 17280 KB Output is correct
54 Correct 15 ms 17280 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 16768 KB Output is correct
2 Correct 11 ms 16768 KB Output is correct
3 Correct 12 ms 16768 KB Output is correct
4 Correct 12 ms 16896 KB Output is correct
5 Correct 12 ms 16768 KB Output is correct
6 Correct 13 ms 16768 KB Output is correct
7 Correct 13 ms 16768 KB Output is correct
8 Correct 13 ms 16768 KB Output is correct
9 Correct 13 ms 16768 KB Output is correct
10 Correct 12 ms 16768 KB Output is correct
11 Correct 12 ms 16768 KB Output is correct
12 Correct 12 ms 16768 KB Output is correct
13 Correct 13 ms 16788 KB Output is correct
14 Correct 13 ms 16768 KB Output is correct
15 Correct 13 ms 16768 KB Output is correct
16 Correct 13 ms 16768 KB Output is correct
17 Correct 13 ms 16768 KB Output is correct
18 Correct 13 ms 16768 KB Output is correct
19 Correct 12 ms 16840 KB Output is correct
20 Correct 12 ms 16768 KB Output is correct
21 Correct 13 ms 16768 KB Output is correct
22 Correct 12 ms 16768 KB Output is correct
23 Correct 12 ms 16768 KB Output is correct
24 Correct 13 ms 16768 KB Output is correct
25 Correct 12 ms 16768 KB Output is correct
26 Correct 13 ms 16768 KB Output is correct
27 Correct 12 ms 16768 KB Output is correct
28 Correct 12 ms 16768 KB Output is correct
29 Correct 12 ms 16768 KB Output is correct
30 Correct 12 ms 16852 KB Output is correct
31 Correct 13 ms 16896 KB Output is correct
32 Correct 13 ms 17024 KB Output is correct
33 Correct 16 ms 16896 KB Output is correct
34 Correct 13 ms 17024 KB Output is correct
35 Correct 14 ms 17024 KB Output is correct
36 Correct 14 ms 17024 KB Output is correct
37 Correct 18 ms 17152 KB Output is correct
38 Correct 16 ms 17152 KB Output is correct
39 Correct 14 ms 17152 KB Output is correct
40 Correct 13 ms 17024 KB Output is correct
41 Correct 16 ms 17024 KB Output is correct
42 Correct 14 ms 17024 KB Output is correct
43 Correct 15 ms 17152 KB Output is correct
44 Correct 14 ms 17152 KB Output is correct
45 Correct 15 ms 17152 KB Output is correct
46 Correct 15 ms 17280 KB Output is correct
47 Correct 15 ms 17280 KB Output is correct
48 Correct 18 ms 17152 KB Output is correct
49 Correct 15 ms 17280 KB Output is correct
50 Correct 14 ms 17152 KB Output is correct
51 Correct 14 ms 17152 KB Output is correct
52 Correct 14 ms 17152 KB Output is correct
53 Correct 15 ms 17280 KB Output is correct
54 Correct 15 ms 17280 KB Output is correct
55 Correct 24 ms 17792 KB Output is correct
56 Correct 51 ms 20840 KB Output is correct
57 Correct 75 ms 23540 KB Output is correct
58 Correct 110 ms 25716 KB Output is correct
59 Correct 125 ms 28528 KB Output is correct
60 Correct 167 ms 31476 KB Output is correct
61 Correct 187 ms 33644 KB Output is correct
62 Correct 251 ms 35432 KB Output is correct
63 Correct 264 ms 39116 KB Output is correct
64 Correct 281 ms 39916 KB Output is correct
65 Correct 132 ms 33400 KB Output is correct
66 Correct 137 ms 33528 KB Output is correct
67 Correct 130 ms 33400 KB Output is correct
68 Correct 219 ms 37540 KB Output is correct
69 Correct 250 ms 37736 KB Output is correct
70 Correct 245 ms 37608 KB Output is correct
71 Correct 281 ms 52608 KB Output is correct
72 Correct 271 ms 52320 KB Output is correct
73 Correct 243 ms 48732 KB Output is correct
74 Correct 247 ms 48732 KB Output is correct
75 Correct 252 ms 47972 KB Output is correct
76 Correct 245 ms 47908 KB Output is correct
77 Correct 251 ms 47076 KB Output is correct
78 Correct 249 ms 45796 KB Output is correct
79 Correct 242 ms 44368 KB Output is correct