제출 #954356

#제출 시각아이디문제언어결과실행 시간메모리
954356GasmaskChan은행 (IZhO14_bank)C++17
71 / 100
1093 ms8500 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define MAX 21 int a[MAX], b[MAX]; vector<int> sum[MAX * 1000]; bitset<1 << MAX> f[MAX]; void dfs(int i, int mask, int &n) { if (i == n) { cout << "YES\n"; exit(0); } 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 << "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...