제출 #915616

#제출 시각아이디문제언어결과실행 시간메모리
915616lamter은행 (IZhO14_bank)C++17
100 / 100
359 ms90832 KiB
#include <bits/stdc++.h> int main(void) { std::ios_base::sync_with_stdio(0); std::cin.tie(nullptr); int n, m; std::cin >> n >> m; std::vector <int> a(n), b(m); for (int& ai : a) std::cin >> ai; for (int& bi : b) std::cin >> bi; std::vector <std::vector <int>> mask(n); for (int x = 0; x < (1 << m); x += 1) { int sum = 0; for (int i = 0; i < m; i += 1) sum += ((x >> i) & 1) * b[i]; for (int i = 0; i < n; i += 1) if (a[i] == sum) mask[i].push_back(x); } std::vector <std::vector <int>> dp(n + 1, std::vector <int> (1 << m)); dp[0][0] = 1; for (int i = 0; i < n; i += 1) for (int x = 0; x < (1 << m); x += 1) if (dp[i][x] == 1) { for (int y : mask[i]) if ((x & y) == 0) dp[i + 1][x | y] = 1; } std::cout << (*std::max_element(dp[n].begin(), dp[n].end()) ? "YES" : "NO"); return 0^0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...