# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
133902 | 2019-07-21T17:13:36 Z | duality | Candies (JOI18_candies) | C++11 | 169 ms | 11052 KB |
#include <bits/stdc++.h> using namespace std; #define mp make_pair #define pb push_back typedef long long int LLI; typedef vector<int> vi; typedef pair<int,int> pii; typedef vector<pii> vpii; 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)) { H.push(mp(rs[l[a]]-d+rs[b],mp(l[a],r[b]))); rs[l[a]] = rs[l[a]]-d+rs[b]; } } return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | 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 | 504 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 | 424 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 | 504 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 | 504 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 | 424 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 | 504 KB | Output is correct |
20 | Correct | 3 ms | 504 KB | Output is correct |
21 | Correct | 146 ms | 10852 KB | Output is correct |
22 | Correct | 145 ms | 10972 KB | Output is correct |
23 | Correct | 147 ms | 10844 KB | Output is correct |
24 | Correct | 108 ms | 10844 KB | Output is correct |
25 | Correct | 108 ms | 10844 KB | Output is correct |
26 | Correct | 107 ms | 10716 KB | Output is correct |
27 | Correct | 120 ms | 10988 KB | Output is correct |
28 | Correct | 120 ms | 10956 KB | Output is correct |
29 | Correct | 124 ms | 11052 KB | Output is correct |
30 | Correct | 122 ms | 10980 KB | Output is correct |
31 | Correct | 123 ms | 10976 KB | Output is correct |
32 | Correct | 122 ms | 10896 KB | Output is correct |
33 | Correct | 133 ms | 10844 KB | Output is correct |
34 | Correct | 143 ms | 10816 KB | Output is correct |
35 | Correct | 146 ms | 10816 KB | Output is correct |
36 | Correct | 161 ms | 11020 KB | Output is correct |
37 | Correct | 169 ms | 10972 KB | Output is correct |
38 | Correct | 145 ms | 10972 KB | Output is correct |
39 | Correct | 107 ms | 10856 KB | Output is correct |
40 | Correct | 107 ms | 10788 KB | Output is correct |
41 | Correct | 108 ms | 10720 KB | Output is correct |
42 | Correct | 120 ms | 10972 KB | Output is correct |
43 | Correct | 122 ms | 10948 KB | Output is correct |
44 | Correct | 119 ms | 10944 KB | Output is correct |
45 | Correct | 121 ms | 10972 KB | Output is correct |
46 | Correct | 124 ms | 11000 KB | Output is correct |
47 | Correct | 133 ms | 10944 KB | Output is correct |
48 | Correct | 135 ms | 10744 KB | Output is correct |
49 | Correct | 135 ms | 10672 KB | Output is correct |
50 | Correct | 156 ms | 10740 KB | Output is correct |