제출 #1282087

#제출 시각아이디문제언어결과실행 시간메모리
1282087lukasuliashviliFestival (IOI25_festival)C++20
컴파일 에러
0 ms0 KiB
#include <vector> #include <algorithm> std::vector<int> max_coupons(int A, std::vector<int> P, std::vector<int> T) { int N = P.size(); bool is_sub1 = std::all_of(T.begin(), T.end(), [](int t) { return t == 1; }); if (is_sub1) { std::vector<std::pair<int, int>> items; for (int i = 0; i < N; ++i) items.emplace_back(P[i], i); std::sort(items.begin(), items.end()); std::vector<int> res; for (auto& [price, idx] : items) { if (A >= price) { A -= price; res.push_back(idx); } else break; } return res; } if (N <= 20) { std::vector<int> indices(N); for (int i = 0; i < N; ++i) indices[i] = i; std::vector<int> best; do { int tokens = A; std::vector<int> used; for (int i = 0; i < N; ++i) { int idx = indices[i]; if (tokens >= P[idx]) { tokens = (tokens - P[idx]) * T[idx]; used.push_back(idx); } else break; } if (used.size() > best.size()) best = used; } while (std::next_permutation(indices.begin(), indices.end())); return best; } std::vector<int> result, current_path; std::vector<bool> used(N, false); std::function<void(int)> dfs = [&](int tokens) { if (current_path.size() > result.size()) result = current_path; for (int i = 0; i < N; ++i) { if (!used[i] && tokens >= P[i]) { used[i] = true; current_path.push_back(i); dfs((tokens - P[i]) * T[i]); current_path.pop_back(); used[i] = false; } } }; dfs(A); return result; }

컴파일 시 표준 에러 (stderr) 메시지

festival.cpp: In function 'std::vector<int> max_coupons(int, std::vector<int>, std::vector<int>)':
festival.cpp:46:10: error: 'function' is not a member of 'std'
   46 |     std::function<void(int)> dfs = [&](int tokens) {
      |          ^~~~~~~~
festival.cpp:3:1: note: 'std::function' is defined in header '<functional>'; did you forget to '#include <functional>'?
    2 | #include <algorithm>
  +++ |+#include <functional>
    3 | 
festival.cpp:46:19: error: expected primary-expression before 'void'
   46 |     std::function<void(int)> dfs = [&](int tokens) {
      |                   ^~~~
festival.cpp:59:5: error: 'dfs' was not declared in this scope
   59 |     dfs(A);
      |     ^~~