Submission #640099

#TimeUsernameProblemLanguageResultExecution timeMemory
640099rilakkumaBank (IZhO14_bank)C++14
100 / 100
709 ms220312 KiB
# include <bits/stdc++.h> using namespace std; typedef long long ll; # define int long long # define For(i, n) for(int i=0; i<n; i++) # define Fori(i, n) for(int i=1; i<=n; i++) # define Each(x, v) for(auto x : v) int n, m, a[25], b[25], memo[25][(1<<20)+5]; vector<int> bitmasks[20005]; int dp(int i, int mask){ if(i==n) return 1; int &res = memo[i][mask]; if(res != -1) return res; res = 0; for(int bit : bitmasks[a[i]]){ if((bit & mask) != 0) continue; res = max(res, dp(i+1, mask | bit)); } return res; } signed main(){ ios_base :: sync_with_stdio(false); memset(memo, -1, sizeof(memo)); 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 sum = 0; for(int i=0; i<m; i++) if((mask >> i)&1) sum += b[i]; bitmasks[sum].push_back(mask); } if(dp(0,0) == 1) cout << "YES" << endl; else cout << "NO" << endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...