Submission #1131534

#TimeUsernameProblemLanguageResultExecution timeMemory
1131534micro7Bank (IZhO14_bank)C++20
71 / 100
1093 ms6576 KiB
#include <iostream> #include <vector> using namespace std; constexpr int MAXN = 20, MAXM = 20; int n, m, a[MAXN + 1], b[MAXM]; bool dp[MAXN + 1][1 << MAXM]; vector<int> configs[1001]; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cin >> n >> m; for (int i = 1; i <= n; ++i) { cin >> a[i]; } for (int i = 0; i < m; ++i) { cin >> b[i]; } for (int s = 0; s < (1 << m); ++s) { int val = 0; for (int i = 0; i < m; ++i) { if (s & (1 << i)) { val += b[i]; } } if (val <= 1000) { configs[val].push_back(s); } } dp[0][0] = true; for (int i = 1; i <= n; ++i) { for (int s = 0; s < (1 << m); ++s) { for (auto j : configs[a[i]]) { if ((s & j) != j) { continue; } if (dp[i - 1][s ^ j]) { dp[i][s] = true; break; } } if (i == n && dp[i][s]) { cout << "YES"; return 0; } } cout << '\n'; } cout << "NO"; return 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...