답안 #187110

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
187110 2020-01-12T12:52:23 Z Akashi Candies (JOI18_candies) C++14
100 / 100
164 ms 10356 KB
#include <bits/stdc++.h>
using namespace std;

const long long INF = 1e18;

int n;
long long a[200005];
int Left[200005], Right[200005];
priority_queue <pair <long long, int> > pq;

int main()
{
    scanf("%d", &n);

    for(int i = 1; i <= n ; ++i){
        scanf("%lld", &a[i]);
        Left[i] = i - 1; Right[i] = i + 1;
        pq.push({a[i], i});
    }

    a[0] = a[n + 1] = -INF;
    long long Sol = 0;
    for(int i = 1; i <= (n + 1) / 2 ; ++i){
        while(!pq.empty() && a[pq.top().second] != pq.top().first) pq.pop();
        int pos = pq.top().second;
        pq.pop();
        Sol += a[pos];
        printf("%lld\n", Sol);

        int L = Left[pos], R = Right[pos];
        Left[pos] = Left[L]; Right[pos] = Right[R];
        Right[Left[L]] = pos; Left[Right[R]] = pos;

        a[pos] = max(a[L] + a[R] - a[pos], -INF);
        a[L] = a[R] = -INF;
        pq.push({a[pos], pos});
    }

    return 0;
}

Compilation message

candies.cpp: In function 'int main()':
candies.cpp:13:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &n);
     ~~~~~^~~~~~~~~~
candies.cpp:16:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%lld", &a[i]);
         ~~~~~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 476 KB Output is correct
2 Correct 9 ms 504 KB Output is correct
3 Correct 3 ms 376 KB Output is correct
4 Correct 5 ms 504 KB Output is correct
5 Correct 4 ms 504 KB Output is correct
6 Correct 4 ms 504 KB Output is correct
7 Correct 4 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 1 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 376 KB Output is correct
16 Correct 3 ms 504 KB Output is correct
17 Correct 3 ms 504 KB Output is correct
18 Correct 2 ms 380 KB Output is correct
19 Correct 3 ms 504 KB Output is correct
20 Correct 4 ms 504 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 476 KB Output is correct
2 Correct 9 ms 504 KB Output is correct
3 Correct 3 ms 376 KB Output is correct
4 Correct 5 ms 504 KB Output is correct
5 Correct 4 ms 504 KB Output is correct
6 Correct 4 ms 504 KB Output is correct
7 Correct 4 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 1 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 376 KB Output is correct
16 Correct 3 ms 504 KB Output is correct
17 Correct 3 ms 504 KB Output is correct
18 Correct 2 ms 380 KB Output is correct
19 Correct 3 ms 504 KB Output is correct
20 Correct 4 ms 504 KB Output is correct
21 Correct 153 ms 10196 KB Output is correct
22 Correct 164 ms 10204 KB Output is correct
23 Correct 155 ms 10112 KB Output is correct
24 Correct 112 ms 9956 KB Output is correct
25 Correct 142 ms 10048 KB Output is correct
26 Correct 126 ms 10076 KB Output is correct
27 Correct 151 ms 10204 KB Output is correct
28 Correct 127 ms 10356 KB Output is correct
29 Correct 129 ms 10204 KB Output is correct
30 Correct 129 ms 10204 KB Output is correct
31 Correct 133 ms 10324 KB Output is correct
32 Correct 117 ms 10076 KB Output is correct
33 Correct 141 ms 9948 KB Output is correct
34 Correct 141 ms 10072 KB Output is correct
35 Correct 138 ms 10088 KB Output is correct
36 Correct 156 ms 9948 KB Output is correct
37 Correct 158 ms 10192 KB Output is correct
38 Correct 155 ms 10064 KB Output is correct
39 Correct 112 ms 10076 KB Output is correct
40 Correct 113 ms 10008 KB Output is correct
41 Correct 120 ms 10160 KB Output is correct
42 Correct 126 ms 9944 KB Output is correct
43 Correct 129 ms 9952 KB Output is correct
44 Correct 130 ms 10020 KB Output is correct
45 Correct 127 ms 9948 KB Output is correct
46 Correct 129 ms 9956 KB Output is correct
47 Correct 157 ms 10060 KB Output is correct
48 Correct 137 ms 9240 KB Output is correct
49 Correct 144 ms 9160 KB Output is correct
50 Correct 143 ms 9144 KB Output is correct