Submission #669179

#TimeUsernameProblemLanguageResultExecution timeMemory
669179irmuunBank (IZhO14_bank)C++17
100 / 100
495 ms103048 KiB
#include<bits/stdc++.h> using namespace std; #define ll long long #define pb push_back int main(){ int n,m; cin>>n>>m; int a[n+5],b[m+5]; for(int i=0;i<n;i++){ cin>>a[i]; } for(int i=0;i<m;i++){ cin>>b[i]; } vector<int>v[n+5]; for(int i=0;i<(1<<m);i++){ int cur=0; for(int j=0;j<m;j++){ if((i&(1<<j))>0){ cur+=b[j]; } } for(int j=0;j<n;j++){ if(a[j]==cur){ v[j].pb(i); } } } for(int i=0;i<n;i++){ if(v[i].size()==0){ cout<<"NO"; return 0; } } int dp[m+5][(1<<m)+5]; for(int i=0;i<m;i++){ fill(dp[i],dp[i]+(1<<m)+1,0); } for(auto x:v[0]){ dp[0][x]=1; } for(int i=1;i<n;i++){ for(int j=0;j<(1<<m);j++){ if(dp[i-1][j]==0){ continue; } for(auto x:v[i]){ if((x&j)==0){ dp[i][x+j]=1; } } } } for(int i=0;i<(1<<m);i++){ if(dp[n-1][i]==1){ cout<<"YES"; return 0; } } cout<<"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...