답안 #963885

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
963885 2024-04-16T01:48:23 Z abczz Candies (JOI18_candies) C++14
0 / 100
3 ms 4440 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;
      }
      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 Incorrect 3 ms 4440 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 4440 KB Output isn't correct
2 Halted 0 ms 0 KB -