답안 #1106018

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1106018 2024-10-28T21:33:47 Z LaviniaTornaghi Fireworks (APIO16_fireworks) C++17
컴파일 오류
0 ms 0 KB
#include <bits/stdc++.h>
using namespace std;

#define int i64

typedef long long i64;

signed main() {
  ios_base::sync_with_stdio(false); cin.tie(NULL);
  int N, M; cin >> N >> M;

  vector<vector<int>> adj(N);
  vector<int> t(N + M);

  for (int i = 1; i < N + M; i++) {
    int p; cin >> p >> t[i];
    adj[p - 1].push_back(i);
  }

  auto dfs = [&](auto &&dfs, int node) {
    priority_queue<i64> q;
    if (node >= N) {
      q.push(t[node]);
      q.push(t[node]);
      return q;
    }

    for (auto child: adj[node]) {
      priority_queue<i64> cq = dfs(dfs, child);
      
      if (q.size() < cq.size())
      	swap(q, cq);
      while (!cq.empty()) {
        q.push(cq.top());
        cq.pop();
      }
    }
    for (int i = 0; i < adj[node].size() - 1; i++) q.pop();

    i64 x1 = q.top(); q.pop();
    i64 x0 = q.top(); q.pop();

    q.push(x0 + t[node]);
    q.push(x1 + t[node]);

    return q;
  };

  priority<i64> q = dfs(dfs, 0);
  vector<i64> slope_changes;
  while (!q.empty()) {
    int x = q.top(); q.pop();
    slope_changes.push_back(x);
  }

  reverse(slope_changes.begin(), slope_changes.end());
  int curr_slope = 1 - (int)slope_changes.size();
  i64 last_point = 0;
  i64 curr_value = accumulate(t.begin(), t.end(), 0LL);
  i64 best_value = curr_value;

  for (auto x: slope_changes) {
    curr_value += curr_slope * (x - last_point);
    best_value = min(best_value, curr_value);

    last_point = x;
    curr_slope++;
  }

  cout << best_value << '\n';
}

Compilation message

fireworks.cpp: In function 'int main()':
fireworks.cpp:49:3: error: 'priority' was not declared in this scope
   49 |   priority<i64> q = dfs(dfs, 0);
      |   ^~~~~~~~
fireworks.cpp:49:15: error: expected primary-expression before '>' token
   49 |   priority<i64> q = dfs(dfs, 0);
      |               ^
fireworks.cpp:49:17: error: 'q' was not declared in this scope
   49 |   priority<i64> q = dfs(dfs, 0);
      |                 ^
fireworks.cpp: In instantiation of 'main()::<lambda(auto:23&&, i64)> [with auto:23 = main()::<lambda(auto:23&&, i64)>&; i64 = long long int]':
fireworks.cpp:49:31:   required from here
fireworks.cpp:38:23: warning: comparison of integer expressions of different signedness: 'i64' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   38 |     for (int i = 0; i < adj[node].size() - 1; i++) q.pop();
      |                     ~~^~~~~~~~~~~~~~~~~~~~~~