Submission #916620

#TimeUsernameProblemLanguageResultExecution timeMemory
916620atomBank (IZhO14_bank)C++17
100 / 100
413 ms848 KiB
#include "bits/stdc++.h" // @JASPER'S BOILERPLATE using namespace std; using ll = long long; #ifdef JASPER #include "debug.h" #else #define debug(...) 166 #endif const int N = 22; int n, m; int a[N], b[N]; vector <int> adj[N]; // dp(i, x): (1..i person with mask x of bank notes); signed main() { cin.tie(0) -> sync_with_stdio(0); cin >> n >> m; for (int i = 0; i < n; ++i) cin >> a[i]; for (int j = 0; j < m; ++j) cin >> b[j]; for (int msk = 0; msk < (1 << m); ++msk) { int sum = 0; for (int j = 0; j < m; ++j) { if (msk & (1 << j)) { sum += b[j]; } } for (int i = 0; i < n; ++i) { if (sum == a[i]) adj[i].push_back(msk); } } vector <bool> dp(1 << m, 0); dp[0] = 1; for (int i = 0; i < n; ++i) { vector <bool> nxt_dp(1 << m, 0); for (int msk = 0; msk < (1 << m); ++msk) { if (!dp[msk]) continue; for (int valid_msk : adj[i]) { if (!(valid_msk & msk)) nxt_dp[msk | valid_msk] = 1; } } swap(nxt_dp, dp); } bool ans = 0; for (int msk = 0; msk < (1 << m); ++msk) { if (dp[msk]) { ans = 1; break; } } cout << (ans? "YES\n" : "NO\n"); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...