답안 #114643

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
114643 2019-06-02T06:11:14 Z maruii Candies (JOI18_candies) C++14
100 / 100
193 ms 8672 KB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pli = pair<ll, int>;
#define ff first
#define ss second

int L[200005], R[200005];
ll A[200005], ans;
bool used[200005];
priority_queue<pli> pq;

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0);
	int N; cin >> N;
	for (int i = 1; i <= N; ++i) cin >> A[i], pq.emplace(A[i], i);
	iota(L + 1, L + N + 1, 0);
	iota(R, R + N + 1, 1);
	A[0] = A[N+1] = -1e18;
	for (int i = 0; i < (N + 1 >> 1); ++i) {
		while (used[pq.top().ss]) pq.pop();
		int x = pq.top().ss; pq.pop();
		used[L[x]] = used[R[x]] = 1;
		ans += A[x];
		A[x] = A[L[x]] + A[R[x]] - A[x];
		L[x] = L[L[x]];
		R[L[x]] = x;
		R[x] = R[R[x]];
		L[R[x]] = x;
		cout << ans << '\n';
		pq.emplace(A[x], x);
	}
	return 0;
}

Compilation message

candies.cpp: In function 'int main()':
candies.cpp:20:25: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  for (int i = 0; i < (N + 1 >> 1); ++i) {
                       ~~^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 512 KB Output is correct
2 Correct 2 ms 512 KB Output is correct
3 Correct 2 ms 512 KB Output is correct
4 Correct 3 ms 428 KB Output is correct
5 Correct 2 ms 512 KB Output is correct
6 Correct 3 ms 512 KB Output is correct
7 Correct 3 ms 484 KB Output is correct
8 Correct 3 ms 512 KB Output is correct
9 Correct 3 ms 536 KB Output is correct
10 Correct 3 ms 512 KB Output is correct
11 Correct 2 ms 512 KB Output is correct
12 Correct 3 ms 512 KB Output is correct
13 Correct 3 ms 512 KB Output is correct
14 Correct 3 ms 512 KB Output is correct
15 Correct 4 ms 512 KB Output is correct
16 Correct 3 ms 484 KB Output is correct
17 Correct 3 ms 512 KB Output is correct
18 Correct 3 ms 512 KB Output is correct
19 Correct 3 ms 512 KB Output is correct
20 Correct 3 ms 512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 512 KB Output is correct
2 Correct 2 ms 512 KB Output is correct
3 Correct 2 ms 512 KB Output is correct
4 Correct 3 ms 428 KB Output is correct
5 Correct 2 ms 512 KB Output is correct
6 Correct 3 ms 512 KB Output is correct
7 Correct 3 ms 484 KB Output is correct
8 Correct 3 ms 512 KB Output is correct
9 Correct 3 ms 536 KB Output is correct
10 Correct 3 ms 512 KB Output is correct
11 Correct 2 ms 512 KB Output is correct
12 Correct 3 ms 512 KB Output is correct
13 Correct 3 ms 512 KB Output is correct
14 Correct 3 ms 512 KB Output is correct
15 Correct 4 ms 512 KB Output is correct
16 Correct 3 ms 484 KB Output is correct
17 Correct 3 ms 512 KB Output is correct
18 Correct 3 ms 512 KB Output is correct
19 Correct 3 ms 512 KB Output is correct
20 Correct 3 ms 512 KB Output is correct
21 Correct 122 ms 8572 KB Output is correct
22 Correct 130 ms 8512 KB Output is correct
23 Correct 118 ms 8512 KB Output is correct
24 Correct 90 ms 8544 KB Output is correct
25 Correct 95 ms 8672 KB Output is correct
26 Correct 193 ms 8512 KB Output is correct
27 Correct 110 ms 8672 KB Output is correct
28 Correct 109 ms 8548 KB Output is correct
29 Correct 112 ms 8564 KB Output is correct
30 Correct 105 ms 8672 KB Output is correct
31 Correct 102 ms 8544 KB Output is correct
32 Correct 106 ms 8592 KB Output is correct
33 Correct 106 ms 8572 KB Output is correct
34 Correct 103 ms 8516 KB Output is correct
35 Correct 116 ms 8552 KB Output is correct
36 Correct 127 ms 8516 KB Output is correct
37 Correct 128 ms 8548 KB Output is correct
38 Correct 117 ms 8544 KB Output is correct
39 Correct 90 ms 8648 KB Output is correct
40 Correct 98 ms 8544 KB Output is correct
41 Correct 88 ms 8528 KB Output is correct
42 Correct 100 ms 8568 KB Output is correct
43 Correct 114 ms 8668 KB Output is correct
44 Correct 110 ms 8500 KB Output is correct
45 Correct 115 ms 8624 KB Output is correct
46 Correct 96 ms 8544 KB Output is correct
47 Correct 100 ms 8568 KB Output is correct
48 Correct 118 ms 8420 KB Output is correct
49 Correct 120 ms 8548 KB Output is correct
50 Correct 115 ms 8420 KB Output is correct