Submission #1133478

#TimeUsernameProblemLanguageResultExecution timeMemory
1133478domblyBank (IZhO14_bank)C++20
52 / 100
1093 ms1352 KiB
#include <bits/stdc++.h> #define int long long #define F first #define S second #define pb push_back using namespace std; const int N = 5000 + 10; const int inf = 1e15; const int mod = 1e9 + 7; signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n,m; cin >> n >> m; vector<int>a(n),b(m); for(int i = 0; i < n; i++) cin >> a[i]; for(int i = 0; i < m; i++) cin >> b[i]; bool dp[n][1 << m]; for(int i = 0; i < n; i++) { for(int j = 0; j < (1 << m); j++) dp[i][j] = false; } for(int i = 0; i < n; i++) { for(int j = 0; j < (1 << m); j++) { int s = 0; for(int k = 0; k < m; k++) { if((1 << k) & j) s += b[k]; } if(s == a[i]) { for(int msk = 0; msk < (1 << m); msk++) { if((msk & j) == j) { if(i == 0) { dp[i][msk] = true; }else { dp[i][msk] |= dp[i - 1][msk ^ j]; } } } } } } cout << (dp[n - 1][(1 << m) - 1] ? "YES" : "NO"); 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...