제출 #535337

#제출 시각아이디문제언어결과실행 시간메모리
535337nicolexxuu은행 (IZhO14_bank)C++14
27 / 100
1094 ms7072 KiB
#include <bits/stdc++.h> #define MAXN 21 using namespace std; int a[MAXN], b[MAXN]; bool possible[MAXN][1 << MAXN]; vector<int> combos[MAXN * 1000]; int N, M; int main() { ios_base::sync_with_stdio(0); cin.tie(NULL); 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 & (1 << i)) sum += b[i]; } combos[sum].push_back(mask); } possible[0][0] = true; bool res = false; for(int i = 0; i < N; i++) { res = false; for(int mask = 1; mask < (1 << M); mask++) { for(int combo : combos[a[i]]) { if((combo & mask) == combo) possible[i+1][mask] |= res |= possible[i][mask - combo]; } } } if(res) cout << "YES\n"; else cout << "NO\n"; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...