Submission #659140

#TimeUsernameProblemLanguageResultExecution timeMemory
659140ajab_01Bank (IZhO14_bank)C++17
100 / 100
524 ms9712 KiB
#include<bits/stdc++.h> using namespace std; const int N = 21; vector<int> sub[N]; long long pre[N]; bool dp[(1 << N)] , flg; long long sm[(1 << N)] , a[N] , b[N] , n , m; 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]; pre[0] = a[0]; for(int i = 1 ; i < n ; i++) pre[i] = pre[i - 1] + a[i]; for(int mask = 0 ; mask < (1 << m) ; mask++) dp[mask] = 1; for(int mask = 0 ; mask < (1 << m) ; mask++) for(int i = 0 ; i < m ; i++) if(mask & (1 << i)) sm[mask] += b[i]; for(int mask = 0 ; mask < (1 << m) ; mask++) for(int i = 0 ; i < n ; i++) if(sm[mask] == a[i]) sub[i].push_back(mask); for(int i = 0 ; i < n ; i++){ for(int mask = (1 << m) - 1 ; mask >= 0 ; mask--){ if(pre[i] == sm[mask]){ bool ch = 0; for(int val : sub[i]) if((mask & val) == val && dp[mask ^ val]) ch = 1; dp[mask] = ch; } else{ dp[mask] = 0; } if(i == n - 1 && dp[mask]) flg = 1; } } if(!flg) cout << "NO" << '\n'; else cout << "YES" << '\n'; 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...