답안 #506016

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
506016 2022-01-11T11:53:36 Z sidon Candies (JOI18_candies) C++17
100 / 100
198 ms 11380 KB
#include <bits/stdc++.h>
using namespace std;
#define Z 200'002

int64_t N, K, L[Z], R[Z], r[Z], A[Z], sum;
priority_queue<array<int64_t, 2>> pq;

int main() {
	cin >> N;

	for(int i = 1; i <= N; i++) {
		cin >> A[i];
		L[i] = i - 1, R[i] = i + 1;
		pq.push({A[i], i});
	}
 
	R[N+1] = N+1, L[N+1] = N;
	R[0] = r[0] = r[N+1] = 1;
 
	for(int k = 1; k*2 <= N+1; k++) {
		while(r[pq.top()[1]]) pq.pop();
		auto [v, i] = pq.top(); pq.pop();
 
		cout << (sum += v) << '\n';
		r[i] = r[L[i]] || r[R[i]];
		if(!r[L[i]]) v -= A[L[i]], r[L[i]] = 1, R[L[i] = L[L[i]]] = i;
		if(!r[R[i]]) v -= A[R[i]], r[R[i]] = 1, L[R[i] = R[R[i]]] = i;

		if(!r[i]) pq.push({A[i] = -v, i});
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 460 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 2 ms 460 KB Output is correct
4 Correct 2 ms 460 KB Output is correct
5 Correct 3 ms 460 KB Output is correct
6 Correct 2 ms 420 KB Output is correct
7 Correct 1 ms 460 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 3 ms 460 KB Output is correct
10 Correct 1 ms 460 KB Output is correct
11 Correct 2 ms 460 KB Output is correct
12 Correct 2 ms 460 KB Output is correct
13 Correct 2 ms 460 KB Output is correct
14 Correct 2 ms 460 KB Output is correct
15 Correct 2 ms 460 KB Output is correct
16 Correct 2 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 460 KB Output is correct
19 Correct 1 ms 460 KB Output is correct
20 Correct 2 ms 460 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 460 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 2 ms 460 KB Output is correct
4 Correct 2 ms 460 KB Output is correct
5 Correct 3 ms 460 KB Output is correct
6 Correct 2 ms 420 KB Output is correct
7 Correct 1 ms 460 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 3 ms 460 KB Output is correct
10 Correct 1 ms 460 KB Output is correct
11 Correct 2 ms 460 KB Output is correct
12 Correct 2 ms 460 KB Output is correct
13 Correct 2 ms 460 KB Output is correct
14 Correct 2 ms 460 KB Output is correct
15 Correct 2 ms 460 KB Output is correct
16 Correct 2 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 460 KB Output is correct
19 Correct 1 ms 460 KB Output is correct
20 Correct 2 ms 460 KB Output is correct
21 Correct 198 ms 11208 KB Output is correct
22 Correct 159 ms 11200 KB Output is correct
23 Correct 174 ms 11268 KB Output is correct
24 Correct 135 ms 11380 KB Output is correct
25 Correct 127 ms 11224 KB Output is correct
26 Correct 131 ms 11212 KB Output is correct
27 Correct 145 ms 11360 KB Output is correct
28 Correct 134 ms 11256 KB Output is correct
29 Correct 135 ms 11300 KB Output is correct
30 Correct 156 ms 11296 KB Output is correct
31 Correct 157 ms 11280 KB Output is correct
32 Correct 138 ms 11284 KB Output is correct
33 Correct 136 ms 11176 KB Output is correct
34 Correct 146 ms 11260 KB Output is correct
35 Correct 177 ms 11268 KB Output is correct
36 Correct 168 ms 11316 KB Output is correct
37 Correct 164 ms 11212 KB Output is correct
38 Correct 173 ms 11268 KB Output is correct
39 Correct 128 ms 11268 KB Output is correct
40 Correct 139 ms 11192 KB Output is correct
41 Correct 134 ms 11212 KB Output is correct
42 Correct 158 ms 11324 KB Output is correct
43 Correct 139 ms 11296 KB Output is correct
44 Correct 133 ms 11188 KB Output is correct
45 Correct 137 ms 11236 KB Output is correct
46 Correct 146 ms 11240 KB Output is correct
47 Correct 134 ms 11256 KB Output is correct
48 Correct 142 ms 11176 KB Output is correct
49 Correct 137 ms 11304 KB Output is correct
50 Correct 162 ms 11308 KB Output is correct