답안 #963911

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
963911 2024-04-16T02:56:04 Z abczz Candies (JOI18_candies) C++14
100 / 100
140 ms 11984 KB
#include <iostream>
#include <queue>
#include <array>
#define ll long long
 
using namespace std;
 
priority_queue <array<ll, 2>> pq;
bool B[200000];
ll n, f, A[200000], pre[200000], nx[200000];
 
void linkerase(ll u) {
  B[u] = 1;
  if (pre[u] != -1) nx[pre[u]] = nx[u];
  if (nx[u] < n) pre[nx[u]] = pre[u];
}
 
int main() {
  cin >> n;
  for (int i=0; i<n; ++i) {
    cin >> A[i];
    pre[i] = i-1, nx[i] = i+1;
    pq.push({A[i], i});
  }
  for (int i=0; i<(n+1)/2; ++i) {
    while (true) {
      auto [w, u] = pq.top();
      pq.pop();
      if (B[u]) continue;
      f += w;
      if (pre[u] != -1 && nx[u] < n) {
        pq.push({A[pre[u]]+A[nx[u]]-w, u});
        A[u] = A[pre[u]]+A[nx[u]]-w;
      }
      else linkerase(u);
      if (pre[u] != -1) linkerase(pre[u]);
      if (nx[u] < n) linkerase(nx[u]);
      cout << f << '\n';
      break;
    }
  }
}

Compilation message

candies.cpp: In function 'int main()':
candies.cpp:27:12: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   27 |       auto [w, u] = pq.top();
      |            ^
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 2 ms 2396 KB Output is correct
3 Correct 1 ms 460 KB Output is correct
4 Correct 2 ms 604 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 2 ms 2392 KB Output is correct
7 Correct 2 ms 604 KB Output is correct
8 Correct 1 ms 600 KB Output is correct
9 Correct 1 ms 604 KB Output is correct
10 Correct 2 ms 604 KB Output is correct
11 Correct 1 ms 600 KB Output is correct
12 Correct 2 ms 2396 KB Output is correct
13 Correct 2 ms 2396 KB Output is correct
14 Correct 2 ms 604 KB Output is correct
15 Correct 2 ms 600 KB Output is correct
16 Correct 2 ms 604 KB Output is correct
17 Correct 1 ms 600 KB Output is correct
18 Correct 2 ms 348 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 2392 KB Output is correct
2 Correct 2 ms 2396 KB Output is correct
3 Correct 1 ms 460 KB Output is correct
4 Correct 2 ms 604 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 2 ms 2392 KB Output is correct
7 Correct 2 ms 604 KB Output is correct
8 Correct 1 ms 600 KB Output is correct
9 Correct 1 ms 604 KB Output is correct
10 Correct 2 ms 604 KB Output is correct
11 Correct 1 ms 600 KB Output is correct
12 Correct 2 ms 2396 KB Output is correct
13 Correct 2 ms 2396 KB Output is correct
14 Correct 2 ms 604 KB Output is correct
15 Correct 2 ms 600 KB Output is correct
16 Correct 2 ms 604 KB Output is correct
17 Correct 1 ms 600 KB Output is correct
18 Correct 2 ms 348 KB Output is correct
19 Correct 1 ms 604 KB Output is correct
20 Correct 1 ms 604 KB Output is correct
21 Correct 118 ms 11956 KB Output is correct
22 Correct 120 ms 11788 KB Output is correct
23 Correct 120 ms 11984 KB Output is correct
24 Correct 126 ms 11800 KB Output is correct
25 Correct 100 ms 11816 KB Output is correct
26 Correct 108 ms 11724 KB Output is correct
27 Correct 119 ms 11876 KB Output is correct
28 Correct 109 ms 11796 KB Output is correct
29 Correct 123 ms 11956 KB Output is correct
30 Correct 117 ms 11888 KB Output is correct
31 Correct 106 ms 11788 KB Output is correct
32 Correct 115 ms 11940 KB Output is correct
33 Correct 110 ms 11724 KB Output is correct
34 Correct 121 ms 11804 KB Output is correct
35 Correct 106 ms 11704 KB Output is correct
36 Correct 112 ms 11964 KB Output is correct
37 Correct 112 ms 11884 KB Output is correct
38 Correct 121 ms 11848 KB Output is correct
39 Correct 98 ms 11712 KB Output is correct
40 Correct 99 ms 11668 KB Output is correct
41 Correct 108 ms 11816 KB Output is correct
42 Correct 106 ms 11960 KB Output is correct
43 Correct 140 ms 11780 KB Output is correct
44 Correct 111 ms 11764 KB Output is correct
45 Correct 110 ms 11960 KB Output is correct
46 Correct 107 ms 11964 KB Output is correct
47 Correct 108 ms 11856 KB Output is correct
48 Correct 105 ms 11704 KB Output is correct
49 Correct 118 ms 11700 KB Output is correct
50 Correct 103 ms 11704 KB Output is correct