답안 #134405

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
134405 2019-07-22T16:15:15 Z duality Candies (JOI18_candies) C++11
100 / 100
152 ms 11000 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 A[200000];
int l[200001],r[200001];
LLI rs[200001];
priority_queue<pair<LLI,pii> > H;
int main() {
    int i;
    int N;
    scanf("%d",&N);
    for (i = 0; i < N; i++) scanf("%d",&A[i]);

    LLI ans = 0;
    for (i = 0; i <= N; i++) {
        l[i] = i-1,r[i] = i+1;
        if (i < N) rs[i] = A[i],H.push(mp(A[i],mp(i,i+1)));
    }
    while (!H.empty()) {
        int a = H.top().second.first,b = H.top().second.second;
        LLI d = H.top().first;
        H.pop();

        if ((r[a] != b) || (l[b] != a)) continue;
        ans += d,printf("%lld\n",ans);
        if (l[a] != -1) r[l[a]] = r[b];
        if (r[b] != N+1) l[r[b]] = l[a];
        if ((l[a] != -1) && (r[b] != N+1)) {
            rs[l[a]] += rs[b]-d;
            H.push(mp(rs[l[a]],mp(l[a],r[b])));
        }
    }

    return 0;
}

Compilation message

candies.cpp: In function 'int main()':
candies.cpp:65:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d",&N);
     ~~~~~^~~~~~~~~
candies.cpp:66:34: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     for (i = 0; i < N; i++) scanf("%d",&A[i]);
                             ~~~~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 504 KB Output is correct
2 Correct 3 ms 504 KB Output is correct
3 Correct 3 ms 504 KB Output is correct
4 Correct 3 ms 508 KB Output is correct
5 Correct 3 ms 504 KB Output is correct
6 Correct 3 ms 636 KB Output is correct
7 Correct 3 ms 504 KB Output is correct
8 Correct 3 ms 504 KB Output is correct
9 Correct 3 ms 504 KB Output is correct
10 Correct 3 ms 504 KB Output is correct
11 Correct 3 ms 504 KB Output is correct
12 Correct 3 ms 504 KB Output is correct
13 Correct 3 ms 504 KB Output is correct
14 Correct 3 ms 504 KB Output is correct
15 Correct 3 ms 504 KB Output is correct
16 Correct 3 ms 504 KB Output is correct
17 Correct 3 ms 504 KB Output is correct
18 Correct 3 ms 504 KB Output is correct
19 Correct 3 ms 476 KB Output is correct
20 Correct 3 ms 504 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 504 KB Output is correct
2 Correct 3 ms 504 KB Output is correct
3 Correct 3 ms 504 KB Output is correct
4 Correct 3 ms 508 KB Output is correct
5 Correct 3 ms 504 KB Output is correct
6 Correct 3 ms 636 KB Output is correct
7 Correct 3 ms 504 KB Output is correct
8 Correct 3 ms 504 KB Output is correct
9 Correct 3 ms 504 KB Output is correct
10 Correct 3 ms 504 KB Output is correct
11 Correct 3 ms 504 KB Output is correct
12 Correct 3 ms 504 KB Output is correct
13 Correct 3 ms 504 KB Output is correct
14 Correct 3 ms 504 KB Output is correct
15 Correct 3 ms 504 KB Output is correct
16 Correct 3 ms 504 KB Output is correct
17 Correct 3 ms 504 KB Output is correct
18 Correct 3 ms 504 KB Output is correct
19 Correct 3 ms 476 KB Output is correct
20 Correct 3 ms 504 KB Output is correct
21 Correct 152 ms 11000 KB Output is correct
22 Correct 147 ms 10972 KB Output is correct
23 Correct 147 ms 10972 KB Output is correct
24 Correct 108 ms 10716 KB Output is correct
25 Correct 108 ms 10724 KB Output is correct
26 Correct 108 ms 10716 KB Output is correct
27 Correct 121 ms 10976 KB Output is correct
28 Correct 122 ms 10916 KB Output is correct
29 Correct 118 ms 10924 KB Output is correct
30 Correct 119 ms 10972 KB Output is correct
31 Correct 118 ms 10908 KB Output is correct
32 Correct 121 ms 10936 KB Output is correct
33 Correct 133 ms 10768 KB Output is correct
34 Correct 132 ms 10844 KB Output is correct
35 Correct 131 ms 10788 KB Output is correct
36 Correct 142 ms 10972 KB Output is correct
37 Correct 150 ms 10972 KB Output is correct
38 Correct 148 ms 10944 KB Output is correct
39 Correct 110 ms 10844 KB Output is correct
40 Correct 114 ms 10796 KB Output is correct
41 Correct 107 ms 10808 KB Output is correct
42 Correct 119 ms 10872 KB Output is correct
43 Correct 117 ms 10972 KB Output is correct
44 Correct 118 ms 10920 KB Output is correct
45 Correct 121 ms 10996 KB Output is correct
46 Correct 119 ms 10976 KB Output is correct
47 Correct 118 ms 10968 KB Output is correct
48 Correct 135 ms 10696 KB Output is correct
49 Correct 128 ms 10768 KB Output is correct
50 Correct 131 ms 10716 KB Output is correct