Submission #672924

#TimeUsernameProblemLanguageResultExecution timeMemory
672924viwlesxqBank (IZhO14_bank)C++17
100 / 100
489 ms30552 KiB
#include "bits/stdc++.h" using namespace std; typedef long long ll; typedef string str; #define pb push_back #define pf push_front #define ppb pop_back #define ppf pop_front #define F first #define S second #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() #define sz(x) (int)x.size() int n, m; vector <int> g[20]; int a[20], b[20]; bool used[20][(1 << 20)], res[20][(1 << 20)]; bool dfs(int mask, int v) { if (v == n) return true; if (used[v][mask]) return res[v][mask]; used[v][mask] = true; bool cur = false; for (int to : g[v]) { if (to & mask) continue; if (dfs(to ^ mask, v + 1)) cur = true; } return res[v][mask] = cur; } signed main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> 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 cur = 0; for (int i = 0; i < m; i++) { if (mask & (1 << i)) cur += b[i]; } for (int i = 0; i < n; i++) { if (a[i] == cur) g[i].pb(mask); } } dfs(0, 0); bool flag = false; for (bool i : res[n-1]) { if (i) flag = true; } if (flag) cout << "YES"; else cout << "NO"; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...