답안 #1035082

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1035082 2024-07-26T04:00:33 Z juicy Candies (JOI18_candies) C++17
100 / 100
72 ms 10480 KB
#include <bits/stdc++.h>

using namespace std;

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

const int N = 2e5 + 5;
const long long inf = 1e18;

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});
  }
  a[0] = a[n + 1] = -inf;
  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();
    }
    cout << (res += pq.top().first) << "\n";
    int u = pq.top().second;
    pq.pop();
    int lt = L[u], rt = R[u];
    pq.push({a[u] = a[lt] + a[rt] - a[u], u});
    app(lt);
    app(rt);
  }
  return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2392 KB Output is correct
5 Correct 1 ms 2392 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2604 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2392 KB Output is correct
5 Correct 1 ms 2392 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 1 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2604 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 1 ms 2396 KB Output is correct
19 Correct 1 ms 2396 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 66 ms 10268 KB Output is correct
22 Correct 72 ms 10436 KB Output is correct
23 Correct 68 ms 10288 KB Output is correct
24 Correct 54 ms 10192 KB Output is correct
25 Correct 63 ms 10180 KB Output is correct
26 Correct 54 ms 10176 KB Output is correct
27 Correct 60 ms 10480 KB Output is correct
28 Correct 63 ms 10240 KB Output is correct
29 Correct 61 ms 10432 KB Output is correct
30 Correct 59 ms 10448 KB Output is correct
31 Correct 60 ms 10432 KB Output is correct
32 Correct 59 ms 10252 KB Output is correct
33 Correct 60 ms 10156 KB Output is correct
34 Correct 60 ms 10180 KB Output is correct
35 Correct 60 ms 10248 KB Output is correct
36 Correct 66 ms 10372 KB Output is correct
37 Correct 65 ms 10292 KB Output is correct
38 Correct 65 ms 10332 KB Output is correct
39 Correct 52 ms 10176 KB Output is correct
40 Correct 51 ms 10192 KB Output is correct
41 Correct 50 ms 10180 KB Output is correct
42 Correct 61 ms 10432 KB Output is correct
43 Correct 58 ms 10428 KB Output is correct
44 Correct 59 ms 10432 KB Output is correct
45 Correct 66 ms 10268 KB Output is correct
46 Correct 61 ms 10292 KB Output is correct
47 Correct 60 ms 10428 KB Output is correct
48 Correct 60 ms 10196 KB Output is correct
49 Correct 61 ms 10172 KB Output is correct
50 Correct 63 ms 10176 KB Output is correct