Submission #220898

# Submission time Handle Problem Language Result Execution time Memory
220898 2020-04-09T07:57:57 Z PeppaPig Candies (JOI18_candies) C++14
100 / 100
404 ms 19576 KB
#include <bits/stdc++.h>

#define long long long
#define pii pair<long, long>
#define x first
#define y second

using namespace std;

const int N = 2e5+5;

int n, L[N], R[N];
long A[N];
set<pii> S;

int main() {
    scanf("%d", &n);
    for(int i = 1; i <= n; i++) {
        scanf("%lld", A + i);
        if(i > 1) L[i] = i - 1;
        if(i < n) R[i] = i + 1;
        S.emplace(A[i], i);
    }
    long ans = 0;
    for(int i = 1; i <= (n + 1) / 2; i++) {
        int now = S.rbegin()->y;
        printf("%lld\n", ans += A[now]);
        S.erase(pii(A[now], now));
        int l = L[now], r = R[now];
        if(l) S.erase(pii(A[l], l));
        if(r) S.erase(pii(A[r], r));
        A[now] = A[l] + A[r] - A[now];
        if(l && r) {
            L[now] = L[l], R[now] = R[r];
            S.emplace(A[now], now);
        } else now = 0;
        if(L[l]) R[L[l]] = now;
        if(R[r]) L[R[r]] = now;
    }

    return 0;
}

Compilation message

candies.cpp: In function 'int main()':
candies.cpp:17:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &n);
     ~~~~~^~~~~~~~~~
candies.cpp:19:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%lld", A + i);
         ~~~~~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 6 ms 512 KB Output is correct
2 Correct 6 ms 512 KB Output is correct
3 Correct 6 ms 512 KB Output is correct
4 Correct 6 ms 512 KB Output is correct
5 Correct 6 ms 512 KB Output is correct
6 Correct 6 ms 512 KB Output is correct
7 Correct 6 ms 512 KB Output is correct
8 Correct 8 ms 512 KB Output is correct
9 Correct 6 ms 512 KB Output is correct
10 Correct 6 ms 512 KB Output is correct
11 Correct 6 ms 512 KB Output is correct
12 Correct 6 ms 512 KB Output is correct
13 Correct 6 ms 512 KB Output is correct
14 Correct 6 ms 512 KB Output is correct
15 Correct 6 ms 512 KB Output is correct
16 Correct 6 ms 512 KB Output is correct
17 Correct 6 ms 512 KB Output is correct
18 Correct 6 ms 512 KB Output is correct
19 Correct 6 ms 512 KB Output is correct
20 Correct 6 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 512 KB Output is correct
2 Correct 6 ms 512 KB Output is correct
3 Correct 6 ms 512 KB Output is correct
4 Correct 6 ms 512 KB Output is correct
5 Correct 6 ms 512 KB Output is correct
6 Correct 6 ms 512 KB Output is correct
7 Correct 6 ms 512 KB Output is correct
8 Correct 8 ms 512 KB Output is correct
9 Correct 6 ms 512 KB Output is correct
10 Correct 6 ms 512 KB Output is correct
11 Correct 6 ms 512 KB Output is correct
12 Correct 6 ms 512 KB Output is correct
13 Correct 6 ms 512 KB Output is correct
14 Correct 6 ms 512 KB Output is correct
15 Correct 6 ms 512 KB Output is correct
16 Correct 6 ms 512 KB Output is correct
17 Correct 6 ms 512 KB Output is correct
18 Correct 6 ms 512 KB Output is correct
19 Correct 6 ms 512 KB Output is correct
20 Correct 6 ms 512 KB Output is correct
21 Correct 404 ms 19380 KB Output is correct
22 Correct 378 ms 19576 KB Output is correct
23 Correct 373 ms 19452 KB Output is correct
24 Correct 164 ms 19192 KB Output is correct
25 Correct 179 ms 19192 KB Output is correct
26 Correct 162 ms 19192 KB Output is correct
27 Correct 175 ms 19500 KB Output is correct
28 Correct 178 ms 19448 KB Output is correct
29 Correct 177 ms 19448 KB Output is correct
30 Correct 187 ms 19448 KB Output is correct
31 Correct 192 ms 19448 KB Output is correct
32 Correct 188 ms 19448 KB Output is correct
33 Correct 268 ms 19192 KB Output is correct
34 Correct 276 ms 19192 KB Output is correct
35 Correct 266 ms 19368 KB Output is correct
36 Correct 381 ms 19448 KB Output is correct
37 Correct 400 ms 19448 KB Output is correct
38 Correct 369 ms 19448 KB Output is correct
39 Correct 165 ms 19192 KB Output is correct
40 Correct 173 ms 19384 KB Output is correct
41 Correct 167 ms 19192 KB Output is correct
42 Correct 177 ms 19448 KB Output is correct
43 Correct 182 ms 19516 KB Output is correct
44 Correct 171 ms 19448 KB Output is correct
45 Correct 182 ms 19448 KB Output is correct
46 Correct 186 ms 19448 KB Output is correct
47 Correct 187 ms 19448 KB Output is correct
48 Correct 275 ms 19224 KB Output is correct
49 Correct 272 ms 19236 KB Output is correct
50 Correct 268 ms 19192 KB Output is correct