제출 #541167

#제출 시각아이디문제언어결과실행 시간메모리
541167status_coding은행 (IZhO14_bank)C++14
0 / 100
1093 ms10524 KiB
#include <bits/stdc++.h> using namespace std; int n,m; int a[22], b[22]; vector<int> fr[1005]; int dp[2000005]; int main() { cin>>n>>m; for(int i=1;i<=n;i++) cin>>a[i]; for(int i=1;i<=m;i++) cin>>b[i]; for(int mask=0; mask < (1<<m); mask++) { int sum = 0; for(int k=0;k<m;k++) if((mask>>k)&1) sum += b[k]; if(sum <= 1000) fr[sum].push_back(sum); } for(int mask=0; mask < (1<<m); mask++) dp[mask]=true; for(int i=1;i<=n;i++) { for(int mask = (1<<m) - 1; mask>=0; mask--) { dp[mask] = false; for(int nmask : fr[a[i]]) if( (mask | nmask) == mask && dp[mask ^ nmask] ) { dp[mask] = true; break; } } } if(dp[ (1<<m) - 1 ]) cout<<"YES"; else cout<<"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...