Submission #848015

#TimeUsernameProblemLanguageResultExecution timeMemory
848015_hbk06Bank (IZhO14_bank)C++14
52 / 100
1048 ms10576 KiB
#include<bits/stdc++.h> using namespace std; const int mxN = 5e5 + 5; #define int long long #define MASK(n) (1 << (n)) #define BIT(mask,x) ((mask >> x) & 1) const long long infll = 1e18 + 69; int n; int m; int a[20]; int b[20]; int s[MASK(20)]; bool dp[MASK(20)][20]; signed main () { //freopen("bank.in","r",stdin); //freopen("bank.out","w",stdout); 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 mask = 0; mask < MASK(m); mask++) for (int j = 0; j < m; j++) if(BIT(mask,j)) s[mask] += b[j]; dp[0][0] = 1; for (int mask = 0; mask < MASK(m); mask++) for (int sub = mask; sub; sub = (sub - 1) & mask) for (int i = 1; i <= n; i++) { if(s[sub] == a[i] && dp[mask ^ sub][i - 1]) dp[mask][i] = true; } bool kt = false; for (int mask = 0; mask < MASK(m); mask++) if(dp[mask][n]) {kt = true;break;} if(kt) cout << "YES" << "\n"; else cout << "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...