답안 #687864

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
687864 2023-01-27T03:19:24 Z wenqi Candies (JOI18_candies) C++17
100 / 100
93 ms 10360 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});
    }
    A[0] = A[N + 1] = -1e17;
    L[0] = 0;
    R[0] = 1;
    L[N + 1] = N;
    R[N + 1] = N + 1;
    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;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 1 ms 596 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 360 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 1 ms 468 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 472 KB Output is correct
13 Correct 2 ms 468 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 1 ms 468 KB Output is correct
17 Correct 1 ms 468 KB Output is correct
18 Correct 1 ms 476 KB Output is correct
19 Correct 1 ms 472 KB Output is correct
20 Correct 1 ms 468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 1 ms 596 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 360 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 1 ms 468 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 472 KB Output is correct
13 Correct 2 ms 468 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 1 ms 468 KB Output is correct
17 Correct 1 ms 468 KB Output is correct
18 Correct 1 ms 476 KB Output is correct
19 Correct 1 ms 472 KB Output is correct
20 Correct 1 ms 468 KB Output is correct
21 Correct 93 ms 10292 KB Output is correct
22 Correct 86 ms 10312 KB Output is correct
23 Correct 87 ms 10276 KB Output is correct
24 Correct 68 ms 10148 KB Output is correct
25 Correct 66 ms 10156 KB Output is correct
26 Correct 69 ms 10072 KB Output is correct
27 Correct 72 ms 10344 KB Output is correct
28 Correct 75 ms 10356 KB Output is correct
29 Correct 74 ms 10240 KB Output is correct
30 Correct 75 ms 10344 KB Output is correct
31 Correct 80 ms 10340 KB Output is correct
32 Correct 76 ms 10268 KB Output is correct
33 Correct 80 ms 10168 KB Output is correct
34 Correct 82 ms 10040 KB Output is correct
35 Correct 80 ms 10068 KB Output is correct
36 Correct 86 ms 10296 KB Output is correct
37 Correct 91 ms 10336 KB Output is correct
38 Correct 86 ms 10232 KB Output is correct
39 Correct 70 ms 10168 KB Output is correct
40 Correct 67 ms 10164 KB Output is correct
41 Correct 73 ms 10156 KB Output is correct
42 Correct 78 ms 10336 KB Output is correct
43 Correct 72 ms 10360 KB Output is correct
44 Correct 75 ms 10292 KB Output is correct
45 Correct 75 ms 10360 KB Output is correct
46 Correct 73 ms 10300 KB Output is correct
47 Correct 74 ms 10284 KB Output is correct
48 Correct 78 ms 10036 KB Output is correct
49 Correct 79 ms 10096 KB Output is correct
50 Correct 78 ms 10040 KB Output is correct