# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
200082 | 2020-02-05T09:49:33 Z | dennisstar | Candies (JOI18_candies) | C++17 | 145 ms | 11124 KB |
#include <bits/stdc++.h> #define fi first #define se second #define em emplace using namespace std; typedef long long ll; int N, chk[200010], l[200010], r[200010]; ll A[200010], ans; priority_queue<pair<ll, int> > pq; int main() { scanf("%d", &N); for (int i=1; i<=N; i++) scanf("%lld", &A[i]), pq.em(A[i], i), l[i]=i-1, r[i]=i+1; A[0]=A[N+1]=-(1e16); for (int i=(N+1)/2; i; i--) { while (chk[pq.top().se]) pq.pop(); auto k=pq.top(); pq.pop(); ans+=k.fi; printf("%lld\n", ans); chk[l[k.se]]=chk[r[k.se]]=1; A[k.se]=A[l[k.se]]+A[r[k.se]]-A[k.se]; pq.em(A[k.se], k.se); l[k.se]=l[l[k.se]], r[l[k.se]]=k.se; r[k.se]=r[r[k.se]], l[r[k.se]]=k.se; } return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 6 ms | 504 KB | Output is correct |
2 | Correct | 6 ms | 508 KB | Output is correct |
3 | Correct | 6 ms | 504 KB | Output is correct |
4 | Correct | 6 ms | 504 KB | Output is correct |
5 | Correct | 6 ms | 504 KB | Output is correct |
6 | Correct | 6 ms | 508 KB | Output is correct |
7 | Correct | 6 ms | 504 KB | Output is correct |
8 | Correct | 6 ms | 504 KB | Output is correct |
9 | Correct | 6 ms | 508 KB | Output is correct |
10 | Correct | 6 ms | 504 KB | Output is correct |
11 | Correct | 6 ms | 504 KB | Output is correct |
12 | Correct | 6 ms | 504 KB | Output is correct |
13 | Correct | 6 ms | 508 KB | Output is correct |
14 | Correct | 6 ms | 504 KB | Output is correct |
15 | Correct | 5 ms | 504 KB | Output is correct |
16 | Correct | 6 ms | 504 KB | Output is correct |
17 | Correct | 6 ms | 504 KB | Output is correct |
18 | Correct | 6 ms | 504 KB | Output is correct |
19 | Correct | 6 ms | 504 KB | Output is correct |
20 | Correct | 6 ms | 504 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 6 ms | 504 KB | Output is correct |
2 | Correct | 6 ms | 508 KB | Output is correct |
3 | Correct | 6 ms | 504 KB | Output is correct |
4 | Correct | 6 ms | 504 KB | Output is correct |
5 | Correct | 6 ms | 504 KB | Output is correct |
6 | Correct | 6 ms | 508 KB | Output is correct |
7 | Correct | 6 ms | 504 KB | Output is correct |
8 | Correct | 6 ms | 504 KB | Output is correct |
9 | Correct | 6 ms | 508 KB | Output is correct |
10 | Correct | 6 ms | 504 KB | Output is correct |
11 | Correct | 6 ms | 504 KB | Output is correct |
12 | Correct | 6 ms | 504 KB | Output is correct |
13 | Correct | 6 ms | 508 KB | Output is correct |
14 | Correct | 6 ms | 504 KB | Output is correct |
15 | Correct | 5 ms | 504 KB | Output is correct |
16 | Correct | 6 ms | 504 KB | Output is correct |
17 | Correct | 6 ms | 504 KB | Output is correct |
18 | Correct | 6 ms | 504 KB | Output is correct |
19 | Correct | 6 ms | 504 KB | Output is correct |
20 | Correct | 6 ms | 504 KB | Output is correct |
21 | Correct | 138 ms | 10972 KB | Output is correct |
22 | Correct | 139 ms | 10972 KB | Output is correct |
23 | Correct | 145 ms | 10972 KB | Output is correct |
24 | Correct | 100 ms | 10716 KB | Output is correct |
25 | Correct | 104 ms | 10844 KB | Output is correct |
26 | Correct | 104 ms | 10716 KB | Output is correct |
27 | Correct | 108 ms | 10972 KB | Output is correct |
28 | Correct | 109 ms | 10940 KB | Output is correct |
29 | Correct | 115 ms | 10972 KB | Output is correct |
30 | Correct | 117 ms | 10972 KB | Output is correct |
31 | Correct | 110 ms | 10972 KB | Output is correct |
32 | Correct | 114 ms | 10972 KB | Output is correct |
33 | Correct | 133 ms | 10760 KB | Output is correct |
34 | Correct | 125 ms | 10716 KB | Output is correct |
35 | Correct | 122 ms | 10716 KB | Output is correct |
36 | Correct | 142 ms | 11124 KB | Output is correct |
37 | Correct | 144 ms | 10972 KB | Output is correct |
38 | Correct | 139 ms | 10972 KB | Output is correct |
39 | Correct | 104 ms | 10720 KB | Output is correct |
40 | Correct | 105 ms | 10756 KB | Output is correct |
41 | Correct | 104 ms | 10716 KB | Output is correct |
42 | Correct | 112 ms | 10972 KB | Output is correct |
43 | Correct | 108 ms | 10972 KB | Output is correct |
44 | Correct | 107 ms | 10972 KB | Output is correct |
45 | Correct | 110 ms | 10972 KB | Output is correct |
46 | Correct | 121 ms | 10972 KB | Output is correct |
47 | Correct | 117 ms | 11104 KB | Output is correct |
48 | Correct | 126 ms | 10720 KB | Output is correct |
49 | Correct | 138 ms | 10716 KB | Output is correct |
50 | Correct | 128 ms | 10720 KB | Output is correct |