Submission #535341

#TimeUsernameProblemLanguageResultExecution timeMemory
535341nicolexxuuBank (IZhO14_bank)C++14
52 / 100
1082 ms11316 KiB
#include <bits/stdc++.h> #define MAXN 21 using namespace std; int a[MAXN], b[MAXN]; int dp[1 << 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]; combos[0].push_back(0); for(int mask = 1; mask < (1 << M); mask++) { int idx = 0; // cout << "mask: " << mask << endl; while(!(mask & (1 << idx))) idx++; // cout << "idx: " << idx << endl; dp[mask] = dp[mask - (1 << idx)] + b[idx]; combos[dp[mask]].push_back(mask); } possible[0][0] = true; for(int i = 0; i < N; i++) { for(int mask = 1; mask < (1 << M); mask++) { for(int combo : combos[a[i]]) { if((combo & mask) == combo) possible[i+1][mask] |= possible[i][mask - combo]; } } } bool res = false; for(int i = 0; i < (1 << M); i++) res |= possible[N][i]; 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...