Submission #1133357

#TimeUsernameProblemLanguageResultExecution timeMemory
1133357lopkusBank (IZhO14_bank)C++20
71 / 100
1094 ms24900 KiB
#include <bits/stdc++.h> #define int long long using namespace std; signed main() { ios::sync_with_stdio(false); cin.tie(0); int n, m; cin >> n >> m; vector<int> a(n); vector<int> b(m); for(int i = 0; i < n; i++) { cin >> a[i]; } for(int i = 0; i < m; i++) { cin >> b[i]; } int dp[n][(1LL << m)]; for(int i = 0; i < n; i++) { for(int j = 0; j < (1LL << m); j++) { dp[i][j] = 0; } } for(int i = 0; i < n; i++) { for(int j = 0; j < (1LL << m); j++) { int s = 0; for(int q = 0; q < m; q++) { if(j & (1LL << q)) { s += b[q]; } } if(s == a[i]) { if(!i) { dp[i][j] = 1; continue; } for(int bitmask = 0; bitmask < (1LL << m); bitmask++) { if((bitmask & j)) { continue; } dp[i][j ^ bitmask] |= dp[i - 1][bitmask]; } } } } int ok = 0; for(int i = 0; i < (1LL << m); i++) { ok |= dp[n - 1][i]; } if(ok) { cout << "YES"; } else { cout << "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...