Submission #154105

# Submission time Handle Problem Language Result Execution time Memory
154105 2019-09-18T11:16:24 Z mhy908 Fireworks (APIO16_fireworks) C++14
100 / 100
391 ms 85056 KB
#include <bits/stdc++.h>
#define pb push_back
using namespace std;
typedef long long LL;
int n, m;
vector<int> link[300010];
LL cost[300010];
struct dpfunc
{
    LL sty, sta;
    priority_queue<LL> pq;
    void mergefunc(dpfunc &pl)
    {
        sty+=pl.sty;
        sta+=pl.sta;
        while(!pl.pq.empty()){
            pq.push(pl.pq.top());
            pl.pq.pop();
        }
    }
    void makereal(LL c)
    {
        sty+=c;
        LL zeronum, onenum;
        while(1){
            if(pq.size()==-sta-1)break;
            if(pq.size()==-sta)zeronum=pq.top();
            if(pq.size()==-sta+1)onenum=pq.top();
            pq.pop();
        }
        zeronum+=c;
        onenum+=c;
        pq.push(zeronum);
        pq.push(onenum);
    }
    void init(LL st)
    {
        pq.push(st);
        pq.push(st);
        sty=st;
        sta=-1;
    }
}func[300010];
void get_dp(int num)
{
    if(num>n){
        func[num].init(cost[num]);
        return;
    }
    int maxsize=0, maxnum;
    for(int i=0; i<link[num].size(); i++){
        get_dp(link[num][i]);
        int temp=func[link[num][i]].pq.size();
        if(temp>maxsize){
            maxsize=temp;
            maxnum=i;
        }
    }
    swap(func[link[num][0]], func[link[num][maxnum]]);
    swap(func[num], func[link[num][0]]);
    for(int i=1; i<link[num].size(); i++)
        func[num].mergefunc(func[link[num][i]]);
    func[num].makereal(cost[num]);
}
int main()
{
    scanf("%d %d", &n, &m);
    for(int i=2; i<=n+m; i++){
        int k;
        scanf("%d %lld", &k, &cost[i]);
        link[k].pb(i);
    }
    get_dp(1);
    while(1){
        if(func[1].pq.size()==-func[1].sta)break;
        func[1].pq.pop();
    }
    func[1].pq.push(0);
    LL p=0;
    while(func[1].pq.size()>=2){
        p++;
        LL x=func[1].pq.top();
        func[1].pq.pop();
        func[1].sty-=(x-func[1].pq.top())*p;
    }
    printf("%lld", func[1].sty);
}

Compilation message

fireworks.cpp: In member function 'void dpfunc::makereal(LL)':
fireworks.cpp:26:25: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             if(pq.size()==-sta-1)break;
                ~~~~~~~~~^~~~~~~~
fireworks.cpp:27:25: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             if(pq.size()==-sta)zeronum=pq.top();
                ~~~~~~~~~^~~~~~
fireworks.cpp:28:25: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             if(pq.size()==-sta+1)onenum=pq.top();
                ~~~~~~~~~^~~~~~~~
fireworks.cpp: In function 'void get_dp(int)':
fireworks.cpp:51:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0; i<link[num].size(); i++){
                  ~^~~~~~~~~~~~~~~~~
fireworks.cpp:61:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=1; i<link[num].size(); i++)
                  ~^~~~~~~~~~~~~~~~~
fireworks.cpp: In function 'int main()':
fireworks.cpp:75:29: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         if(func[1].pq.size()==-func[1].sta)break;
            ~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~
fireworks.cpp:67: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:70:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d %lld", &k, &cost[i]);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
fireworks.cpp: In function 'void get_dp(int)':
fireworks.cpp:59:51: warning: 'maxnum' may be used uninitialized in this function [-Wmaybe-uninitialized]
     swap(func[link[num][0]], func[link[num][maxnum]]);
                                                   ^
# Verdict Execution time Memory Grader output
1 Correct 26 ms 21368 KB Output is correct
2 Correct 26 ms 21496 KB Output is correct
3 Correct 27 ms 21624 KB Output is correct
4 Correct 26 ms 21496 KB Output is correct
5 Correct 26 ms 21496 KB Output is correct
6 Correct 26 ms 21496 KB Output is correct
7 Correct 27 ms 21508 KB Output is correct
8 Correct 27 ms 21408 KB Output is correct
9 Correct 26 ms 21496 KB Output is correct
10 Correct 23 ms 21512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 22 ms 21496 KB Output is correct
2 Correct 19 ms 21472 KB Output is correct
3 Correct 22 ms 21624 KB Output is correct
4 Correct 21 ms 21496 KB Output is correct
5 Correct 22 ms 21496 KB Output is correct
6 Correct 21 ms 21496 KB Output is correct
7 Correct 22 ms 21496 KB Output is correct
8 Correct 22 ms 21496 KB Output is correct
9 Correct 22 ms 21496 KB Output is correct
10 Correct 22 ms 21496 KB Output is correct
11 Correct 22 ms 21496 KB Output is correct
12 Correct 26 ms 21496 KB Output is correct
13 Correct 22 ms 21496 KB Output is correct
14 Correct 29 ms 21496 KB Output is correct
15 Correct 21 ms 21496 KB Output is correct
16 Correct 22 ms 21496 KB Output is correct
17 Correct 26 ms 21496 KB Output is correct
18 Correct 22 ms 21496 KB Output is correct
19 Correct 24 ms 21496 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 26 ms 21368 KB Output is correct
2 Correct 26 ms 21496 KB Output is correct
3 Correct 27 ms 21624 KB Output is correct
4 Correct 26 ms 21496 KB Output is correct
5 Correct 26 ms 21496 KB Output is correct
6 Correct 26 ms 21496 KB Output is correct
7 Correct 27 ms 21508 KB Output is correct
8 Correct 27 ms 21408 KB Output is correct
9 Correct 26 ms 21496 KB Output is correct
10 Correct 23 ms 21512 KB Output is correct
11 Correct 22 ms 21496 KB Output is correct
12 Correct 19 ms 21472 KB Output is correct
13 Correct 22 ms 21624 KB Output is correct
14 Correct 21 ms 21496 KB Output is correct
15 Correct 22 ms 21496 KB Output is correct
16 Correct 21 ms 21496 KB Output is correct
17 Correct 22 ms 21496 KB Output is correct
18 Correct 22 ms 21496 KB Output is correct
19 Correct 22 ms 21496 KB Output is correct
20 Correct 22 ms 21496 KB Output is correct
21 Correct 22 ms 21496 KB Output is correct
22 Correct 26 ms 21496 KB Output is correct
23 Correct 22 ms 21496 KB Output is correct
24 Correct 29 ms 21496 KB Output is correct
25 Correct 21 ms 21496 KB Output is correct
26 Correct 22 ms 21496 KB Output is correct
27 Correct 26 ms 21496 KB Output is correct
28 Correct 22 ms 21496 KB Output is correct
29 Correct 24 ms 21496 KB Output is correct
30 Correct 22 ms 21496 KB Output is correct
31 Correct 23 ms 21592 KB Output is correct
32 Correct 23 ms 21624 KB Output is correct
33 Correct 24 ms 21624 KB Output is correct
34 Correct 24 ms 21624 KB Output is correct
35 Correct 24 ms 21752 KB Output is correct
36 Correct 24 ms 21752 KB Output is correct
37 Correct 26 ms 21752 KB Output is correct
38 Correct 31 ms 21880 KB Output is correct
39 Correct 30 ms 21880 KB Output is correct
40 Correct 28 ms 22520 KB Output is correct
41 Correct 41 ms 22520 KB Output is correct
42 Correct 26 ms 21752 KB Output is correct
43 Correct 26 ms 22136 KB Output is correct
44 Correct 27 ms 22008 KB Output is correct
45 Correct 26 ms 22008 KB Output is correct
46 Correct 30 ms 22008 KB Output is correct
47 Correct 29 ms 22008 KB Output is correct
48 Correct 30 ms 21880 KB Output is correct
49 Correct 30 ms 22008 KB Output is correct
50 Correct 29 ms 21752 KB Output is correct
51 Correct 30 ms 21752 KB Output is correct
52 Correct 27 ms 21844 KB Output is correct
53 Correct 30 ms 22012 KB Output is correct
54 Correct 25 ms 21888 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 26 ms 21368 KB Output is correct
2 Correct 26 ms 21496 KB Output is correct
3 Correct 27 ms 21624 KB Output is correct
4 Correct 26 ms 21496 KB Output is correct
5 Correct 26 ms 21496 KB Output is correct
6 Correct 26 ms 21496 KB Output is correct
7 Correct 27 ms 21508 KB Output is correct
8 Correct 27 ms 21408 KB Output is correct
9 Correct 26 ms 21496 KB Output is correct
10 Correct 23 ms 21512 KB Output is correct
11 Correct 22 ms 21496 KB Output is correct
12 Correct 19 ms 21472 KB Output is correct
13 Correct 22 ms 21624 KB Output is correct
14 Correct 21 ms 21496 KB Output is correct
15 Correct 22 ms 21496 KB Output is correct
16 Correct 21 ms 21496 KB Output is correct
17 Correct 22 ms 21496 KB Output is correct
18 Correct 22 ms 21496 KB Output is correct
19 Correct 22 ms 21496 KB Output is correct
20 Correct 22 ms 21496 KB Output is correct
21 Correct 22 ms 21496 KB Output is correct
22 Correct 26 ms 21496 KB Output is correct
23 Correct 22 ms 21496 KB Output is correct
24 Correct 29 ms 21496 KB Output is correct
25 Correct 21 ms 21496 KB Output is correct
26 Correct 22 ms 21496 KB Output is correct
27 Correct 26 ms 21496 KB Output is correct
28 Correct 22 ms 21496 KB Output is correct
29 Correct 24 ms 21496 KB Output is correct
30 Correct 22 ms 21496 KB Output is correct
31 Correct 23 ms 21592 KB Output is correct
32 Correct 23 ms 21624 KB Output is correct
33 Correct 24 ms 21624 KB Output is correct
34 Correct 24 ms 21624 KB Output is correct
35 Correct 24 ms 21752 KB Output is correct
36 Correct 24 ms 21752 KB Output is correct
37 Correct 26 ms 21752 KB Output is correct
38 Correct 31 ms 21880 KB Output is correct
39 Correct 30 ms 21880 KB Output is correct
40 Correct 28 ms 22520 KB Output is correct
41 Correct 41 ms 22520 KB Output is correct
42 Correct 26 ms 21752 KB Output is correct
43 Correct 26 ms 22136 KB Output is correct
44 Correct 27 ms 22008 KB Output is correct
45 Correct 26 ms 22008 KB Output is correct
46 Correct 30 ms 22008 KB Output is correct
47 Correct 29 ms 22008 KB Output is correct
48 Correct 30 ms 21880 KB Output is correct
49 Correct 30 ms 22008 KB Output is correct
50 Correct 29 ms 21752 KB Output is correct
51 Correct 30 ms 21752 KB Output is correct
52 Correct 27 ms 21844 KB Output is correct
53 Correct 30 ms 22012 KB Output is correct
54 Correct 25 ms 21888 KB Output is correct
55 Correct 32 ms 22392 KB Output is correct
56 Correct 69 ms 25008 KB Output is correct
57 Correct 107 ms 27468 KB Output is correct
58 Correct 134 ms 29032 KB Output is correct
59 Correct 174 ms 31540 KB Output is correct
60 Correct 231 ms 34152 KB Output is correct
61 Correct 245 ms 36080 KB Output is correct
62 Correct 276 ms 37492 KB Output is correct
63 Correct 365 ms 40556 KB Output is correct
64 Correct 391 ms 41424 KB Output is correct
65 Correct 195 ms 84984 KB Output is correct
66 Correct 203 ms 85056 KB Output is correct
67 Correct 185 ms 38296 KB Output is correct
68 Correct 262 ms 62824 KB Output is correct
69 Correct 308 ms 58960 KB Output is correct
70 Correct 358 ms 58940 KB Output is correct
71 Correct 302 ms 52120 KB Output is correct
72 Correct 290 ms 52224 KB Output is correct
73 Correct 264 ms 48904 KB Output is correct
74 Correct 264 ms 48996 KB Output is correct
75 Correct 265 ms 48024 KB Output is correct
76 Correct 263 ms 47844 KB Output is correct
77 Correct 268 ms 46808 KB Output is correct
78 Correct 266 ms 44392 KB Output is correct
79 Correct 265 ms 46244 KB Output is correct