Submission #595884

#TimeUsernameProblemLanguageResultExecution timeMemory
595884BelphegorBank (IZhO14_bank)C++14
71 / 100
1056 ms24928 KiB
#include<bits/stdc++.h> using namespace std; typedef long long ll; int n,m; int A[22],B[22]; short sum[(1<<20)]; char dp[22][(1<<20)]; char f(int cur,int state){ char&ret = dp[cur][state]; if(~ret) return ret; ret = 0; if(cur==n) return ret = 1; for(int s = state; s; s = (s-1)&state){ if(sum[s]==A[cur]) ret|=f(cur+1,state^s); } return ret; } int main(){ ios_base::sync_with_stdio(false); 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 i=1; i<(1<<m); i++){ int tot = 0; for(int j=0; j<m; j++) if(i&(1<<j)) tot+=B[j]; sum[i] = tot; } memset(dp,-1,sizeof(dp)); cout<<(f(0,(1<<m)-1)?"YES":"NO"); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...