답안 #62234

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
62234 2018-07-27T23:05:08 Z duality Fireworks (APIO16_fireworks) C++11
100 / 100
401 ms 134672 KB
#define DEBUG 0

#include <bits/stdc++.h>
using namespace std;

#if DEBUG
// basic debugging macros
int __i__,__j__;
#define printLine(l) for(__i__=0;__i__<l;__i__++){cout<<"-";}cout<<endl
#define printLine2(l,c) for(__i__=0;__i__<l;__i__++){cout<<c;}cout<<endl
#define printVar(n) cout<<#n<<": "<<n<<endl
#define printArr(a,l) cout<<#a<<": ";for(__i__=0;__i__<l;__i__++){cout<<a[__i__]<<" ";}cout<<endl
#define print2dArr(a,r,c) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<a[__i__][__j__]<<" ";}cout<<endl;}
#define print2dArr2(a,r,c,l) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<setw(l)<<setfill(' ')<<a[__i__][__j__]<<" ";}cout<<endl;}

// advanced debugging class
// debug 1,2,'A',"test";
class _Debug {
    public:
        template<typename T>
        _Debug& operator,(T val) {
            cout << val << endl;
            return *this;
        }
};
#define debug _Debug(),
#else
#define printLine(l)
#define printLine2(l,c)
#define printVar(n)
#define printArr(a,l)
#define print2dArr(a,r,c)
#define print2dArr2(a,r,c,l)
#define debug
#endif

// define
#define MAX_VAL 999999999
#define MAX_VAL_2 999999999999999999LL
#define EPS 1e-6
#define mp make_pair
#define pb push_back

// typedef
typedef unsigned int UI;
typedef long long int LLI;
typedef unsigned long long int ULLI;
typedef unsigned short int US;
typedef pair<int,int> pii;
typedef pair<LLI,LLI> plli;
typedef vector<int> vi;
typedef vector<LLI> vlli;
typedef vector<pii> vpii;
typedef vector<plli> vplli;

// ---------- END OF TEMPLATE ----------

int C[300000];
vpii adjList[300000];
priority_queue<LLI> H[300000];
LLI m[300000],b[300000];
int p[300000];
int main() {
    int i;
    int N,M,P;
    scanf("%d %d",&N,&M);
    for (i = 1; i < N+M; i++) {
        scanf("%d %d",&P,&C[i]);
        adjList[P-1].pb(mp(i,C[i]));
    }

    int j;
    for (i = N; i < N+M; i++) {
        p[i] = i,m[i] = 1,b[i] = -C[i];
        H[i].push(C[i]),H[i].push(C[i]);
    }
    for (i = N-1; i >= 0; i--) {
        int h = -1;
        for (j = 0; j < adjList[i].size(); j++) {
            int v = adjList[i][j].first;
            if ((h == -1) || (H[p[v]].size() > H[p[h]].size())) h = v;
        }
        p[i] = p[h];
        for (j = 0; j < adjList[i].size(); j++) {
            int v = adjList[i][j].first;
            if (v != h) {
                m[p[i]] += m[p[v]],b[p[i]] += b[p[v]];
                while (!H[p[v]].empty()) H[p[i]].push(H[p[v]].top()),H[p[v]].pop();
            }
        }
        while (m[p[i]] > 1) m[p[i]]--,b[p[i]] += H[p[i]].top(),H[p[i]].pop();
        b[p[i]] -= C[i];
        LLI x = H[p[i]].top();
        H[p[i]].pop();
        LLI y = H[p[i]].top();
        H[p[i]].pop();
        H[p[i]].push(x+C[i]),H[p[i]].push(y+C[i]);
    }
    printf("%lld\n",m[p[0]]*H[p[0]].top()+b[p[0]]);

    return 0;
}

Compilation message

fireworks.cpp: In function 'int main()':
fireworks.cpp:79:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (j = 0; j < adjList[i].size(); j++) {
                     ~~^~~~~~~~~~~~~~~~~~~
fireworks.cpp:84:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (j = 0; j < adjList[i].size(); j++) {
                     ~~^~~~~~~~~~~~~~~~~~~
fireworks.cpp:66: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:68:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d %d",&P,&C[i]);
         ~~~~~^~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 16760 KB Output is correct
2 Correct 21 ms 16872 KB Output is correct
3 Correct 17 ms 17100 KB Output is correct
4 Correct 20 ms 17100 KB Output is correct
5 Correct 18 ms 17248 KB Output is correct
6 Correct 18 ms 17248 KB Output is correct
7 Correct 17 ms 17248 KB Output is correct
8 Correct 18 ms 17248 KB Output is correct
9 Correct 23 ms 17248 KB Output is correct
10 Correct 17 ms 17248 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 17248 KB Output is correct
2 Correct 18 ms 17248 KB Output is correct
3 Correct 17 ms 17248 KB Output is correct
4 Correct 18 ms 17248 KB Output is correct
5 Correct 18 ms 17248 KB Output is correct
6 Correct 24 ms 17248 KB Output is correct
7 Correct 18 ms 17248 KB Output is correct
8 Correct 20 ms 17248 KB Output is correct
9 Correct 19 ms 17248 KB Output is correct
10 Correct 17 ms 17248 KB Output is correct
11 Correct 19 ms 17324 KB Output is correct
12 Correct 18 ms 17324 KB Output is correct
13 Correct 19 ms 17324 KB Output is correct
14 Correct 21 ms 17324 KB Output is correct
15 Correct 18 ms 17324 KB Output is correct
16 Correct 22 ms 17324 KB Output is correct
17 Correct 20 ms 17324 KB Output is correct
18 Correct 21 ms 17324 KB Output is correct
19 Correct 18 ms 17324 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 16760 KB Output is correct
2 Correct 21 ms 16872 KB Output is correct
3 Correct 17 ms 17100 KB Output is correct
4 Correct 20 ms 17100 KB Output is correct
5 Correct 18 ms 17248 KB Output is correct
6 Correct 18 ms 17248 KB Output is correct
7 Correct 17 ms 17248 KB Output is correct
8 Correct 18 ms 17248 KB Output is correct
9 Correct 23 ms 17248 KB Output is correct
10 Correct 17 ms 17248 KB Output is correct
11 Correct 18 ms 17248 KB Output is correct
12 Correct 18 ms 17248 KB Output is correct
13 Correct 17 ms 17248 KB Output is correct
14 Correct 18 ms 17248 KB Output is correct
15 Correct 18 ms 17248 KB Output is correct
16 Correct 24 ms 17248 KB Output is correct
17 Correct 18 ms 17248 KB Output is correct
18 Correct 20 ms 17248 KB Output is correct
19 Correct 19 ms 17248 KB Output is correct
20 Correct 17 ms 17248 KB Output is correct
21 Correct 19 ms 17324 KB Output is correct
22 Correct 18 ms 17324 KB Output is correct
23 Correct 19 ms 17324 KB Output is correct
24 Correct 21 ms 17324 KB Output is correct
25 Correct 18 ms 17324 KB Output is correct
26 Correct 22 ms 17324 KB Output is correct
27 Correct 20 ms 17324 KB Output is correct
28 Correct 21 ms 17324 KB Output is correct
29 Correct 18 ms 17324 KB Output is correct
30 Correct 21 ms 17324 KB Output is correct
31 Correct 18 ms 17500 KB Output is correct
32 Correct 19 ms 17500 KB Output is correct
33 Correct 22 ms 17556 KB Output is correct
34 Correct 19 ms 17588 KB Output is correct
35 Correct 20 ms 17648 KB Output is correct
36 Correct 20 ms 17844 KB Output is correct
37 Correct 20 ms 17904 KB Output is correct
38 Correct 19 ms 17972 KB Output is correct
39 Correct 21 ms 18044 KB Output is correct
40 Correct 24 ms 18044 KB Output is correct
41 Correct 21 ms 18116 KB Output is correct
42 Correct 21 ms 18140 KB Output is correct
43 Correct 21 ms 18340 KB Output is correct
44 Correct 22 ms 18412 KB Output is correct
45 Correct 21 ms 18484 KB Output is correct
46 Correct 21 ms 18812 KB Output is correct
47 Correct 24 ms 18876 KB Output is correct
48 Correct 23 ms 18876 KB Output is correct
49 Correct 26 ms 18884 KB Output is correct
50 Correct 23 ms 18944 KB Output is correct
51 Correct 25 ms 18984 KB Output is correct
52 Correct 32 ms 19048 KB Output is correct
53 Correct 28 ms 19140 KB Output is correct
54 Correct 26 ms 19300 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 16760 KB Output is correct
2 Correct 21 ms 16872 KB Output is correct
3 Correct 17 ms 17100 KB Output is correct
4 Correct 20 ms 17100 KB Output is correct
5 Correct 18 ms 17248 KB Output is correct
6 Correct 18 ms 17248 KB Output is correct
7 Correct 17 ms 17248 KB Output is correct
8 Correct 18 ms 17248 KB Output is correct
9 Correct 23 ms 17248 KB Output is correct
10 Correct 17 ms 17248 KB Output is correct
11 Correct 18 ms 17248 KB Output is correct
12 Correct 18 ms 17248 KB Output is correct
13 Correct 17 ms 17248 KB Output is correct
14 Correct 18 ms 17248 KB Output is correct
15 Correct 18 ms 17248 KB Output is correct
16 Correct 24 ms 17248 KB Output is correct
17 Correct 18 ms 17248 KB Output is correct
18 Correct 20 ms 17248 KB Output is correct
19 Correct 19 ms 17248 KB Output is correct
20 Correct 17 ms 17248 KB Output is correct
21 Correct 19 ms 17324 KB Output is correct
22 Correct 18 ms 17324 KB Output is correct
23 Correct 19 ms 17324 KB Output is correct
24 Correct 21 ms 17324 KB Output is correct
25 Correct 18 ms 17324 KB Output is correct
26 Correct 22 ms 17324 KB Output is correct
27 Correct 20 ms 17324 KB Output is correct
28 Correct 21 ms 17324 KB Output is correct
29 Correct 18 ms 17324 KB Output is correct
30 Correct 21 ms 17324 KB Output is correct
31 Correct 18 ms 17500 KB Output is correct
32 Correct 19 ms 17500 KB Output is correct
33 Correct 22 ms 17556 KB Output is correct
34 Correct 19 ms 17588 KB Output is correct
35 Correct 20 ms 17648 KB Output is correct
36 Correct 20 ms 17844 KB Output is correct
37 Correct 20 ms 17904 KB Output is correct
38 Correct 19 ms 17972 KB Output is correct
39 Correct 21 ms 18044 KB Output is correct
40 Correct 24 ms 18044 KB Output is correct
41 Correct 21 ms 18116 KB Output is correct
42 Correct 21 ms 18140 KB Output is correct
43 Correct 21 ms 18340 KB Output is correct
44 Correct 22 ms 18412 KB Output is correct
45 Correct 21 ms 18484 KB Output is correct
46 Correct 21 ms 18812 KB Output is correct
47 Correct 24 ms 18876 KB Output is correct
48 Correct 23 ms 18876 KB Output is correct
49 Correct 26 ms 18884 KB Output is correct
50 Correct 23 ms 18944 KB Output is correct
51 Correct 25 ms 18984 KB Output is correct
52 Correct 32 ms 19048 KB Output is correct
53 Correct 28 ms 19140 KB Output is correct
54 Correct 26 ms 19300 KB Output is correct
55 Correct 33 ms 19872 KB Output is correct
56 Correct 67 ms 23156 KB Output is correct
57 Correct 115 ms 26800 KB Output is correct
58 Correct 159 ms 30328 KB Output is correct
59 Correct 217 ms 34960 KB Output is correct
60 Correct 264 ms 39764 KB Output is correct
61 Correct 248 ms 45184 KB Output is correct
62 Correct 269 ms 49976 KB Output is correct
63 Correct 302 ms 57152 KB Output is correct
64 Correct 401 ms 62468 KB Output is correct
65 Correct 232 ms 62468 KB Output is correct
66 Correct 177 ms 64452 KB Output is correct
67 Correct 200 ms 69292 KB Output is correct
68 Correct 243 ms 78524 KB Output is correct
69 Correct 292 ms 83672 KB Output is correct
70 Correct 347 ms 88500 KB Output is correct
71 Correct 306 ms 109124 KB Output is correct
72 Correct 327 ms 113620 KB Output is correct
73 Correct 294 ms 114224 KB Output is correct
74 Correct 253 ms 118484 KB Output is correct
75 Correct 303 ms 121012 KB Output is correct
76 Correct 311 ms 125060 KB Output is correct
77 Correct 342 ms 127724 KB Output is correct
78 Correct 248 ms 131376 KB Output is correct
79 Correct 238 ms 134672 KB Output is correct