# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
114644 |
2019-06-02T06:12:27 Z |
maruii |
Candies (JOI18_candies) |
C++14 |
|
136 ms |
8648 KB |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pli = pair<ll, int>;
#define ff first
#define ss second
const ll INF = 1e18;
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 + 1, R + N + 1, 2);
A[0] = A[N+1] = -INF;
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';
if (A[x] > -INF) 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 |
512 KB |
Output is correct |
7 |
Correct |
3 ms |
512 KB |
Output is correct |
8 |
Correct |
3 ms |
512 KB |
Output is correct |
9 |
Correct |
3 ms |
512 KB |
Output is correct |
10 |
Correct |
2 ms |
512 KB |
Output is correct |
11 |
Correct |
3 ms |
512 KB |
Output is correct |
12 |
Correct |
2 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 |
3 ms |
512 KB |
Output is correct |
19 |
Correct |
2 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 |
512 KB |
Output is correct |
7 |
Correct |
3 ms |
512 KB |
Output is correct |
8 |
Correct |
3 ms |
512 KB |
Output is correct |
9 |
Correct |
3 ms |
512 KB |
Output is correct |
10 |
Correct |
2 ms |
512 KB |
Output is correct |
11 |
Correct |
3 ms |
512 KB |
Output is correct |
12 |
Correct |
2 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 |
3 ms |
512 KB |
Output is correct |
19 |
Correct |
2 ms |
512 KB |
Output is correct |
20 |
Correct |
3 ms |
512 KB |
Output is correct |
21 |
Correct |
130 ms |
8496 KB |
Output is correct |
22 |
Correct |
129 ms |
8392 KB |
Output is correct |
23 |
Correct |
113 ms |
8416 KB |
Output is correct |
24 |
Correct |
93 ms |
8496 KB |
Output is correct |
25 |
Correct |
93 ms |
8488 KB |
Output is correct |
26 |
Correct |
91 ms |
8384 KB |
Output is correct |
27 |
Correct |
109 ms |
8364 KB |
Output is correct |
28 |
Correct |
111 ms |
8648 KB |
Output is correct |
29 |
Correct |
97 ms |
8412 KB |
Output is correct |
30 |
Correct |
107 ms |
8400 KB |
Output is correct |
31 |
Correct |
112 ms |
8416 KB |
Output is correct |
32 |
Correct |
99 ms |
8340 KB |
Output is correct |
33 |
Correct |
100 ms |
8416 KB |
Output is correct |
34 |
Correct |
104 ms |
8368 KB |
Output is correct |
35 |
Correct |
106 ms |
8448 KB |
Output is correct |
36 |
Correct |
136 ms |
8468 KB |
Output is correct |
37 |
Correct |
126 ms |
8544 KB |
Output is correct |
38 |
Correct |
116 ms |
8448 KB |
Output is correct |
39 |
Correct |
92 ms |
8432 KB |
Output is correct |
40 |
Correct |
93 ms |
8416 KB |
Output is correct |
41 |
Correct |
92 ms |
8508 KB |
Output is correct |
42 |
Correct |
112 ms |
8420 KB |
Output is correct |
43 |
Correct |
111 ms |
8388 KB |
Output is correct |
44 |
Correct |
107 ms |
8396 KB |
Output is correct |
45 |
Correct |
100 ms |
8544 KB |
Output is correct |
46 |
Correct |
96 ms |
8416 KB |
Output is correct |
47 |
Correct |
100 ms |
8460 KB |
Output is correct |
48 |
Correct |
105 ms |
8576 KB |
Output is correct |
49 |
Correct |
103 ms |
8348 KB |
Output is correct |
50 |
Correct |
106 ms |
8364 KB |
Output is correct |