Submission #887775

#TimeUsernameProblemLanguageResultExecution timeMemory
887775viwlesxqBank (IZhO14_bank)C++17
100 / 100
418 ms34204 KiB
#include <bits/stdc++.h> using namespace std; typedef int64_t ll; #define all(x) x.begin(), x.end() #define size(x) (int)x.size() template<class S, class T> bool chmin(S &a, const T &b) { return (a > b ? (a = b) == b : false); } template<class S, class T> bool chmax(S &a, const T &b) { return (a < b ? (a = b) == b : false); } const ll inf = 1e18; const int mod = 1e9 + 7; int n, m; vector<int> a, b, g[20]; bool vis[20][1 << 20], res[20][1 << 20]; bool dfs(int v, int used) { if (v == n) { return true; } if (vis[v][used]) { return res[v][used]; } vis[v][used] = true; bool ret = false; for (int to : g[v]) { if (used & to) { continue; } ret |= dfs(v + 1, used | to); } return res[v][used] = ret; } signed main() { cin.tie(nullptr)->sync_with_stdio(false); cin >> n >> m; a.resize(n), b.resize(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 i = 0; i < m; ++i) { if (mask >> i & 1) { sum += b[i]; } } for (int i = 0; i < n; ++i) { if (sum == a[i]) { g[i].push_back(mask); } } } res[0][0] = dfs(0, 0); bool flag = false; for (int i = 0; i < (1 << m); ++i) { flag |= res[n - 1][i]; } cout << (flag ? "YES" : "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...