제출 #1077904

#제출 시각아이디문제언어결과실행 시간메모리
1077904MyCode은행 (IZhO14_bank)C++17
19 / 100
83 ms7704 KiB
#include <bits/stdc++.h> using namespace std; const int C = 1010; vector<int> good[C]; bool dp[21][(1 << 21)]; signed main() { ios_base::sync_with_stdio(false); cin.tie(nullptr), cout.tie(nullptr); int n, m; cin >> n >> m; int a[n], b[m]; for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < m; i++) cin >> b[i]; for (int mask = 0; mask < (1 << m); mask++) { int sum = 0; for (int j = 0; j < m; j++) sum += ((mask >> j) & 1) * b[j]; if (sum < C) good[sum].emplace_back(mask); } for (int i = 0; i < n; i++) { for (int j = 0; j < (1 << m); j++) dp[i][j] = false; } for (int mask: good[a[0]]) dp[0][mask] = true; for (int j = 0; j < (1 << m); j++) for (int bit = 0; bit < m; bit++) { if (((j >> bit) & 1) == 1 && dp[0][j - (1 << bit)]) { dp[0][j] = true; break; } } for (int i = 1; i < n; i++) { for (int j = 0; j < (1 << m); j++) { dp[i][j] = false; for (int bit = 0; bit < m; bit++) { if (((j >> bit) & 1) == 1 && dp[i][j - (1 << bit)]) { dp[i][j] = true; break; } } if (!dp[i][j]) for (int mask: good[a[i]]) { if ((mask & j) == j && dp[i][j - mask]) { dp[i][j] = true; break; } } } } cout << (dp[n - 1][(1 << m) - 1] ? "YES" : "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...