Submission #170040

#TimeUsernameProblemLanguageResultExecution timeMemory
170040tselmegkhBank (IZhO14_bank)C++14
100 / 100
501 ms34944 KiB
#include<bits/stdc++.h> using namespace std; int a[25], b[25], n, m; bool dp[25][(1 << 21)]; bool vis[25][(1 << 21)]; int sum[(1 << 21)]; vector<int> to[21]; inline bool go(int v, int mask){ if(v == n){ return 1; } if(vis[v][mask])return dp[v][mask]; vis[v][mask] = 1; bool possible = 0; for(int u : to[v]){ if(!(mask & u))possible |= go(v + 1, mask | u); } return dp[v][mask] = possible; } int main(){ ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); 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 i = 0; i < (1 << m); i++){ for(int j = 0; j < m; j++){ if(i & (1 << j)){ sum[i] += b[j]; } } } for(int i = 0; i < n; i++){ for(int j = 0; j < (1 << m); j++){ if(sum[j] == a[i]){ to[i].push_back(j); } } } if(go(0, 0)){ 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...