Submission #1184720

#TimeUsernameProblemLanguageResultExecution timeMemory
1184720versesrevBank (IZhO14_bank)C++20
Compilation error
0 ms0 KiB
#include <iostream> #include <array> #include <map> #include <algorithm> #include <numeric> int main() { int n, m; std::cin >> n >> m; std::vector<int> as(n), bs(m); for (int& a : as) std::cin >> a; for (int& b : bs) std::cin >> b; std::ranges::sort(as), std::ranges::sort(bs); std::map<std::array<int, 21>, bool> table; int a_sum = std::accumulate(as.begin(), as.end(), 0); int b_sum = std::accumulate(bs.begin(), bs.end(), 0); auto brute = [&](auto&& self, const std::array<int, 21>& state) -> bool { if (table.contains(state)) return table[state]; if (b_sum < a_sum) { return table[state] = false; } if (state[0] == m) { return table[state] = (a_sum == 0); } std::array<int, 21> new_state = state; int b = bs[new_state[0]]; ++new_state[0], b_sum -= b; if (brute(new_state)) { return table[state] = true; } for (int i = 1; i < 21; ++i) { if (b < new_state[i]) continue; new_state[i] -= b; int j = i; for (; j > 1 and new_state[j-1] > new_state[j]; --j) { std::swap(new_state[j-1], new_state[j]); } if (brute(new_state)) { return table[state] = true; } for (; j != i; ++j) { if (j != 1) std::swap(new_state[j-1], new_state[j]); } new_state[i] += b; } return table[state] = false; }; std::array<int, 21> state; for (int i = 0; i < n; ++i) state[i] = as[i]; std::ranges::sort(state); bool ans = brute(state); std::cout << "YES\n"; }

Compilation message (stderr)

bank.cpp: In lambda function:
bank.cpp:29:9: error: use of 'brute' before deduction of 'auto'
   29 |     if (brute(new_state)) {
      |         ^~~~~
bank.cpp:39:11: error: use of 'brute' before deduction of 'auto'
   39 |       if (brute(new_state)) { return table[state] = true; }
      |           ^~~~~
bank.cpp: In function 'int main()':
bank.cpp:51:19: error: no match for call to '(main()::<lambda(auto:16&&, const std::array<int, 21>&)>) (std::array<int, 21>&)'
   51 |   bool ans = brute(state);
      |              ~~~~~^~~~~~~
bank.cpp:19:16: note: candidate: 'template<class auto:16> main()::<lambda(auto:16&&, const std::array<int, 21>&)>'
   19 |   auto brute = [&](auto&& self, const std::array<int, 21>& state) -> bool {
      |                ^
bank.cpp:19:16: note:   template argument deduction/substitution failed:
bank.cpp:51:19: note:   candidate expects 2 arguments, 1 provided
   51 |   bool ans = brute(state);
      |              ~~~~~^~~~~~~