제출 #954354

#제출 시각아이디문제언어결과실행 시간메모리
954354GasmaskChan은행 (IZhO14_bank)C++17
71 / 100
1044 ms15964 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #define MAX 21 int a[MAX], b[MAX]; vector<int> sum[MAX * 1000]; bool f[MAX][1 << MAX], flag; void dfs(int i, int mask, int &n) { if (i == n) { flag = true; return; } f[i][mask] = true; for (int other : sum[a[i + 1]]) if ((mask & other) == 0 && !f[i + 1][other]) dfs(i + 1, mask | other, n); } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); // freopen("test.in", "r", stdin); freopen("test.out", "w", stdout); int n, m; 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, mask = 0; mask < (1 << m); mask++) { s = 0; for (int j, cur = mask; cur; cur ^= -cur & cur) { j = __builtin_ctz(cur); s += b[j]; } sum[s].push_back(mask); } dfs(0, 0, n); cout << (flag ? "YES\n" : "NO\n"); 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...