Submission #687867

# Submission time Handle Problem Language Result Execution time Memory
687867 2023-01-27T03:35:09 Z wenqi Candies (JOI18_candies) C++17
100 / 100
101 ms 8460 KB
// trans rights
#include <bits/extc++.h>
using namespace std;
using ll = long long;
using base = complex<double>;
#define up(k, N) for (int k = 1; k <= N; k++)
#define down(k, N) for (int k = N; k >= 1; k--)
#define f0(A) memset(A, 0, sizeof(A))
#define f3(A) memset(A, 0x3f, sizeof(A))
#define all(A) begin(A), end(A)

int N;
ll A[200069];

int L[200069], R[200069];
bool dead[200069];

int main(int argc, const char *argv[])
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> N;
    for (int i = 1; i <= N; i++) cin >> A[i];
    priority_queue<pair<ll, int>> pq;
    for (int i = 1; i <= N; i++) {
        L[i] = i - 1;
        R[i] = i + 1;
        pq.push({A[i], i});
    }
    L[0] = 0;
    R[0] = 1;
    L[N + 1] = N;
    R[N + 1] = N + 1;
    A[0] = A[N + 1] = -1e17;
    ll sum = 0;
    int cnt = 0;
    while (cnt < (N + 1) / 2) {
        auto [w, i] = pq.top();
        pq.pop();

        if (dead[i]) continue;

        sum += w;
        cnt++;
        cout << sum << '\n';

        int l = L[i], r = R[i];
        A[i] = A[l] + A[r] - A[i];
        dead[l] = dead[r] = true;
        L[i] = L[l], R[i] = R[r];
        R[L[i]] = i;
        L[R[i]] = i;
        pq.push({A[i], i});
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 2 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 2 ms 340 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 101 ms 8460 KB Output is correct
22 Correct 82 ms 8364 KB Output is correct
23 Correct 88 ms 8304 KB Output is correct
24 Correct 66 ms 8300 KB Output is correct
25 Correct 66 ms 8324 KB Output is correct
26 Correct 66 ms 8352 KB Output is correct
27 Correct 74 ms 8352 KB Output is correct
28 Correct 76 ms 8292 KB Output is correct
29 Correct 71 ms 8352 KB Output is correct
30 Correct 73 ms 8380 KB Output is correct
31 Correct 72 ms 8376 KB Output is correct
32 Correct 77 ms 8324 KB Output is correct
33 Correct 85 ms 8304 KB Output is correct
34 Correct 78 ms 8288 KB Output is correct
35 Correct 86 ms 8352 KB Output is correct
36 Correct 84 ms 8376 KB Output is correct
37 Correct 83 ms 8328 KB Output is correct
38 Correct 82 ms 8304 KB Output is correct
39 Correct 65 ms 8396 KB Output is correct
40 Correct 67 ms 8284 KB Output is correct
41 Correct 66 ms 8380 KB Output is correct
42 Correct 75 ms 8384 KB Output is correct
43 Correct 72 ms 8364 KB Output is correct
44 Correct 72 ms 8300 KB Output is correct
45 Correct 73 ms 8376 KB Output is correct
46 Correct 72 ms 8300 KB Output is correct
47 Correct 72 ms 8372 KB Output is correct
48 Correct 80 ms 8376 KB Output is correct
49 Correct 78 ms 8332 KB Output is correct
50 Correct 77 ms 8300 KB Output is correct