답안 #1035069

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1035069 2024-07-26T03:43:38 Z juicy Candies (JOI18_candies) C++17
100 / 100
91 ms 10448 KB
#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif

const int N = 2e5 + 5;

int n;
int L[N], R[N];
long long a[N];
bool tog[N];

void app(int u) {
  tog[u] = 1;
  L[R[u]] = L[u];
  R[L[u]] = R[u];
}

int main() {
  ios::sync_with_stdio(false); cin.tie(nullptr);

  cin >> n;
  priority_queue<pair<long long, int>> pq;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
    L[i] = i - 1, R[i] = i + 1;
    pq.push({a[i], i});
  }
  R[n + 1] = n + 1;
  long long res = 0;
  for (int i = 1; i <= (n + 1) / 2; ++i) {
    while (pq.size() && tog[pq.top().second]) {
      pq.pop();
    }
    assert(pq.size());
    cout << (res += pq.top().first) << "\n";
    int u = pq.top().second;
    pq.pop();
    int lt = L[u], rt = R[u];
    if (0 < lt && rt <= n) {
      pq.push({a[u] = a[lt] + a[rt] - a[u], u});
    } else {
      app(u);
    }
    app(lt);
    app(rt);
  }
  return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 608 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 2 ms 600 KB Output is correct
5 Correct 1 ms 600 KB Output is correct
6 Correct 1 ms 600 KB Output is correct
7 Correct 1 ms 476 KB Output is correct
8 Correct 1 ms 604 KB Output is correct
9 Correct 1 ms 604 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Correct 1 ms 476 KB Output is correct
12 Correct 1 ms 604 KB Output is correct
13 Correct 1 ms 604 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Correct 1 ms 436 KB Output is correct
16 Correct 2 ms 600 KB Output is correct
17 Correct 1 ms 600 KB Output is correct
18 Correct 1 ms 604 KB Output is correct
19 Correct 1 ms 604 KB Output is correct
20 Correct 1 ms 604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 608 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 2 ms 600 KB Output is correct
5 Correct 1 ms 600 KB Output is correct
6 Correct 1 ms 600 KB Output is correct
7 Correct 1 ms 476 KB Output is correct
8 Correct 1 ms 604 KB Output is correct
9 Correct 1 ms 604 KB Output is correct
10 Correct 1 ms 604 KB Output is correct
11 Correct 1 ms 476 KB Output is correct
12 Correct 1 ms 604 KB Output is correct
13 Correct 1 ms 604 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Correct 1 ms 436 KB Output is correct
16 Correct 2 ms 600 KB Output is correct
17 Correct 1 ms 600 KB Output is correct
18 Correct 1 ms 604 KB Output is correct
19 Correct 1 ms 604 KB Output is correct
20 Correct 1 ms 604 KB Output is correct
21 Correct 81 ms 10448 KB Output is correct
22 Correct 64 ms 10424 KB Output is correct
23 Correct 60 ms 10428 KB Output is correct
24 Correct 61 ms 10304 KB Output is correct
25 Correct 52 ms 10176 KB Output is correct
26 Correct 44 ms 10120 KB Output is correct
27 Correct 71 ms 10428 KB Output is correct
28 Correct 59 ms 10432 KB Output is correct
29 Correct 61 ms 10308 KB Output is correct
30 Correct 78 ms 10432 KB Output is correct
31 Correct 77 ms 10428 KB Output is correct
32 Correct 66 ms 10352 KB Output is correct
33 Correct 63 ms 10248 KB Output is correct
34 Correct 56 ms 10172 KB Output is correct
35 Correct 57 ms 10248 KB Output is correct
36 Correct 62 ms 10336 KB Output is correct
37 Correct 68 ms 10340 KB Output is correct
38 Correct 91 ms 10428 KB Output is correct
39 Correct 52 ms 10204 KB Output is correct
40 Correct 53 ms 10180 KB Output is correct
41 Correct 48 ms 10172 KB Output is correct
42 Correct 61 ms 10432 KB Output is correct
43 Correct 72 ms 10424 KB Output is correct
44 Correct 55 ms 10432 KB Output is correct
45 Correct 56 ms 10432 KB Output is correct
46 Correct 61 ms 10428 KB Output is correct
47 Correct 74 ms 10428 KB Output is correct
48 Correct 54 ms 10176 KB Output is correct
49 Correct 57 ms 10088 KB Output is correct
50 Correct 63 ms 10060 KB Output is correct