Submission #114641

# Submission time Handle Problem Language Result Execution time Memory
114641 2019-06-02T06:10:45 Z maruii Candies (JOI18_candies) C++14
100 / 100
136 ms 10476 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 + 2, 0);
	iota(R, R + N + 1, 1);
	R[N+1] = N+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:21:25: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  for (int i = 0; i < (N + 1 >> 1); ++i) {
                       ~~^~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 512 KB Output is correct
2 Correct 3 ms 512 KB Output is correct
3 Correct 3 ms 512 KB Output is correct
4 Correct 3 ms 512 KB Output is correct
5 Correct 3 ms 512 KB Output is correct
6 Correct 3 ms 504 KB Output is correct
7 Correct 3 ms 496 KB Output is correct
8 Correct 2 ms 512 KB Output is correct
9 Correct 3 ms 512 KB Output is correct
10 Correct 3 ms 512 KB Output is correct
11 Correct 3 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 3 ms 512 KB Output is correct
16 Correct 3 ms 512 KB Output is correct
17 Correct 3 ms 512 KB Output is correct
18 Correct 4 ms 512 KB Output is correct
19 Correct 3 ms 512 KB Output is correct
20 Correct 3 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 512 KB Output is correct
2 Correct 3 ms 512 KB Output is correct
3 Correct 3 ms 512 KB Output is correct
4 Correct 3 ms 512 KB Output is correct
5 Correct 3 ms 512 KB Output is correct
6 Correct 3 ms 504 KB Output is correct
7 Correct 3 ms 496 KB Output is correct
8 Correct 2 ms 512 KB Output is correct
9 Correct 3 ms 512 KB Output is correct
10 Correct 3 ms 512 KB Output is correct
11 Correct 3 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 3 ms 512 KB Output is correct
16 Correct 3 ms 512 KB Output is correct
17 Correct 3 ms 512 KB Output is correct
18 Correct 4 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 125 ms 10344 KB Output is correct
22 Correct 136 ms 10460 KB Output is correct
23 Correct 131 ms 10336 KB Output is correct
24 Correct 92 ms 10208 KB Output is correct
25 Correct 89 ms 10284 KB Output is correct
26 Correct 88 ms 10340 KB Output is correct
27 Correct 99 ms 10336 KB Output is correct
28 Correct 102 ms 10336 KB Output is correct
29 Correct 101 ms 10368 KB Output is correct
30 Correct 102 ms 10336 KB Output is correct
31 Correct 104 ms 10332 KB Output is correct
32 Correct 103 ms 10336 KB Output is correct
33 Correct 109 ms 10080 KB Output is correct
34 Correct 107 ms 10216 KB Output is correct
35 Correct 106 ms 10160 KB Output is correct
36 Correct 129 ms 10368 KB Output is correct
37 Correct 116 ms 10464 KB Output is correct
38 Correct 113 ms 10340 KB Output is correct
39 Correct 88 ms 10220 KB Output is correct
40 Correct 87 ms 10208 KB Output is correct
41 Correct 88 ms 10220 KB Output is correct
42 Correct 101 ms 10312 KB Output is correct
43 Correct 103 ms 10476 KB Output is correct
44 Correct 103 ms 10372 KB Output is correct
45 Correct 103 ms 10328 KB Output is correct
46 Correct 100 ms 10388 KB Output is correct
47 Correct 106 ms 10336 KB Output is correct
48 Correct 112 ms 10128 KB Output is correct
49 Correct 110 ms 10080 KB Output is correct
50 Correct 121 ms 10168 KB Output is correct