답안 #154108

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
154108 2019-09-18T11:19:14 Z mhy908 Fireworks (APIO16_fireworks) C++14
100 / 100
348 ms 82568 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(pq.size()>=-sta){
            if(pq.size()==-sta)zeronum=pq.top();
            if(pq.size()==-sta+1)onenum=pq.top();
            pq.pop();
        }
        pq.push(zeronum+c);
        pq.push(onenum+c);
    }
    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){
        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:25:24: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         while(pq.size()>=-sta){
               ~~~~~~~~~^~~~~~
fireworks.cpp:26:25: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             if(pq.size()==-sta)zeronum=pq.top();
                ~~~~~~~~~^~~~~~
fireworks.cpp:27: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:48:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0; i<link[num].size(); i++){
                  ~^~~~~~~~~~~~~~~~~
fireworks.cpp:58: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:72:29: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         if(func[1].pq.size()==-func[1].sta)break;
            ~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~
fireworks.cpp:64: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:67: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:31:23: warning: 'onenum' may be used uninitialized in this function [-Wmaybe-uninitialized]
         pq.push(onenum+c);
                 ~~~~~~^~
fireworks.cpp:24:21: note: 'onenum' was declared here
         LL zeronum, onenum;
                     ^~~~~~
fireworks.cpp:30:24: warning: 'zeronum' may be used uninitialized in this function [-Wmaybe-uninitialized]
         pq.push(zeronum+c);
                 ~~~~~~~^~
fireworks.cpp:24:12: note: 'zeronum' was declared here
         LL zeronum, onenum;
            ^~~~~~~
fireworks.cpp:56:51: warning: 'maxnum' may be used uninitialized in this function [-Wmaybe-uninitialized]
     swap(func[link[num][0]], func[link[num][maxnum]]);
                                                   ^
# 결과 실행 시간 메모리 Grader output
1 Correct 21 ms 21544 KB Output is correct
2 Correct 22 ms 21496 KB Output is correct
3 Correct 21 ms 21500 KB Output is correct
4 Correct 21 ms 21424 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 21 ms 21496 KB Output is correct
10 Correct 22 ms 21496 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 21 ms 21496 KB Output is correct
2 Correct 22 ms 21496 KB Output is correct
3 Correct 21 ms 21496 KB Output is correct
4 Correct 22 ms 21516 KB Output is correct
5 Correct 21 ms 21496 KB Output is correct
6 Correct 22 ms 21580 KB Output is correct
7 Correct 21 ms 21496 KB Output is correct
8 Correct 22 ms 21496 KB Output is correct
9 Correct 21 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 22 ms 21500 KB Output is correct
13 Correct 21 ms 21496 KB Output is correct
14 Correct 22 ms 21496 KB Output is correct
15 Correct 22 ms 21440 KB Output is correct
16 Correct 21 ms 21524 KB Output is correct
17 Correct 22 ms 21496 KB Output is correct
18 Correct 21 ms 21496 KB Output is correct
19 Correct 22 ms 21496 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 21 ms 21544 KB Output is correct
2 Correct 22 ms 21496 KB Output is correct
3 Correct 21 ms 21500 KB Output is correct
4 Correct 21 ms 21424 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 21 ms 21496 KB Output is correct
10 Correct 22 ms 21496 KB Output is correct
11 Correct 21 ms 21496 KB Output is correct
12 Correct 22 ms 21496 KB Output is correct
13 Correct 21 ms 21496 KB Output is correct
14 Correct 22 ms 21516 KB Output is correct
15 Correct 21 ms 21496 KB Output is correct
16 Correct 22 ms 21580 KB Output is correct
17 Correct 21 ms 21496 KB Output is correct
18 Correct 22 ms 21496 KB Output is correct
19 Correct 21 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 22 ms 21500 KB Output is correct
23 Correct 21 ms 21496 KB Output is correct
24 Correct 22 ms 21496 KB Output is correct
25 Correct 22 ms 21440 KB Output is correct
26 Correct 21 ms 21524 KB Output is correct
27 Correct 22 ms 21496 KB Output is correct
28 Correct 21 ms 21496 KB Output is correct
29 Correct 22 ms 21496 KB Output is correct
30 Correct 21 ms 21496 KB Output is correct
31 Correct 22 ms 21496 KB Output is correct
32 Correct 22 ms 21624 KB Output is correct
33 Correct 23 ms 21624 KB Output is correct
34 Correct 23 ms 21624 KB Output is correct
35 Correct 24 ms 21708 KB Output is correct
36 Correct 25 ms 21752 KB Output is correct
37 Correct 25 ms 21752 KB Output is correct
38 Correct 29 ms 21964 KB Output is correct
39 Correct 26 ms 21752 KB Output is correct
40 Correct 24 ms 22520 KB Output is correct
41 Correct 24 ms 22548 KB Output is correct
42 Correct 25 ms 21880 KB Output is correct
43 Correct 24 ms 22136 KB Output is correct
44 Correct 29 ms 22264 KB Output is correct
45 Correct 25 ms 21980 KB Output is correct
46 Correct 25 ms 21880 KB Output is correct
47 Correct 29 ms 21980 KB Output is correct
48 Correct 29 ms 21880 KB Output is correct
49 Correct 30 ms 21880 KB Output is correct
50 Correct 25 ms 21752 KB Output is correct
51 Correct 24 ms 21724 KB Output is correct
52 Correct 26 ms 21852 KB Output is correct
53 Correct 25 ms 21880 KB Output is correct
54 Correct 26 ms 21908 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 21 ms 21544 KB Output is correct
2 Correct 22 ms 21496 KB Output is correct
3 Correct 21 ms 21500 KB Output is correct
4 Correct 21 ms 21424 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 21 ms 21496 KB Output is correct
10 Correct 22 ms 21496 KB Output is correct
11 Correct 21 ms 21496 KB Output is correct
12 Correct 22 ms 21496 KB Output is correct
13 Correct 21 ms 21496 KB Output is correct
14 Correct 22 ms 21516 KB Output is correct
15 Correct 21 ms 21496 KB Output is correct
16 Correct 22 ms 21580 KB Output is correct
17 Correct 21 ms 21496 KB Output is correct
18 Correct 22 ms 21496 KB Output is correct
19 Correct 21 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 22 ms 21500 KB Output is correct
23 Correct 21 ms 21496 KB Output is correct
24 Correct 22 ms 21496 KB Output is correct
25 Correct 22 ms 21440 KB Output is correct
26 Correct 21 ms 21524 KB Output is correct
27 Correct 22 ms 21496 KB Output is correct
28 Correct 21 ms 21496 KB Output is correct
29 Correct 22 ms 21496 KB Output is correct
30 Correct 21 ms 21496 KB Output is correct
31 Correct 22 ms 21496 KB Output is correct
32 Correct 22 ms 21624 KB Output is correct
33 Correct 23 ms 21624 KB Output is correct
34 Correct 23 ms 21624 KB Output is correct
35 Correct 24 ms 21708 KB Output is correct
36 Correct 25 ms 21752 KB Output is correct
37 Correct 25 ms 21752 KB Output is correct
38 Correct 29 ms 21964 KB Output is correct
39 Correct 26 ms 21752 KB Output is correct
40 Correct 24 ms 22520 KB Output is correct
41 Correct 24 ms 22548 KB Output is correct
42 Correct 25 ms 21880 KB Output is correct
43 Correct 24 ms 22136 KB Output is correct
44 Correct 29 ms 22264 KB Output is correct
45 Correct 25 ms 21980 KB Output is correct
46 Correct 25 ms 21880 KB Output is correct
47 Correct 29 ms 21980 KB Output is correct
48 Correct 29 ms 21880 KB Output is correct
49 Correct 30 ms 21880 KB Output is correct
50 Correct 25 ms 21752 KB Output is correct
51 Correct 24 ms 21724 KB Output is correct
52 Correct 26 ms 21852 KB Output is correct
53 Correct 25 ms 21880 KB Output is correct
54 Correct 26 ms 21908 KB Output is correct
55 Correct 32 ms 22356 KB Output is correct
56 Correct 68 ms 24976 KB Output is correct
57 Correct 107 ms 27348 KB Output is correct
58 Correct 136 ms 29152 KB Output is correct
59 Correct 176 ms 31600 KB Output is correct
60 Correct 222 ms 33544 KB Output is correct
61 Correct 252 ms 35356 KB Output is correct
62 Correct 297 ms 36420 KB Output is correct
63 Correct 332 ms 38592 KB Output is correct
64 Correct 348 ms 39248 KB Output is correct
65 Correct 185 ms 82568 KB Output is correct
66 Correct 185 ms 82544 KB Output is correct
67 Correct 183 ms 35644 KB Output is correct
68 Correct 256 ms 60520 KB Output is correct
69 Correct 301 ms 56300 KB Output is correct
70 Correct 300 ms 56452 KB Output is correct
71 Correct 288 ms 50168 KB Output is correct
72 Correct 287 ms 50236 KB Output is correct
73 Correct 261 ms 47328 KB Output is correct
74 Correct 286 ms 47336 KB Output is correct
75 Correct 280 ms 46308 KB Output is correct
76 Correct 275 ms 46340 KB Output is correct
77 Correct 263 ms 44772 KB Output is correct
78 Correct 273 ms 42724 KB Output is correct
79 Correct 267 ms 45024 KB Output is correct