제출 #1035738

#제출 시각아이디문제언어결과실행 시간메모리
1035738vanea은행 (IZhO14_bank)C++14
100 / 100
763 ms6972 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; int main() { ios_base::sync_with_stdio(0); cin.tie(0); 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]; } vector<vector<int>> sum(1005); for(int i = 0; i < (1 << m); i++) { int curr = 0; for(int j = 0; j < m; j++) { if(i & (1 << j)) curr += b[j]; } if(curr <= 1000) sum[curr].push_back(i); } vector<bool> dp(1 << m), prev(1 << m); dp[0] = true; for(int i = 0; i < n; i++) { swap(dp, prev); fill(dp.begin(), dp.end(), false); for(auto mask : sum[a[i]]) { for(int mask1 = mask; mask1 < (1 << m); ++mask1 |= mask) { if(prev[mask1^mask]) { dp[mask1] = true; } } } } bool ans = false; for(int i = 0; i < (1 << m); i++) { if(dp[i]) { ans = true; } } cout << (ans ? "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...