Submission #245360

#TimeUsernameProblemLanguageResultExecution timeMemory
245360kshitij_sodani은행 (IZhO14_bank)C++17
100 / 100
179 ms47036 KiB
#include <bits/stdc++.h> using namespace std; typedef int64_t llo; #define mp make_pair #define pb push_back #define a first #define b second //#define endl '\n' int n,m; int dp[21][1<<20]; int aa[21]; int bb[21]; int su[1<<20]; vector<int> pre[1001]; int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); cin>>n>>m; for(int i=0;i<n;i++){ cin>>aa[i]; } for(int i=0;i<m;i++){ cin>>bb[i]; } string ans="NO"; for(int j=0;j<(1<<m);j++){ for(int k=0;k<m;k++){ if((1<<k)&j){ su[j]=su[j-(1<<k)]+bb[k]; break; } } if(su[j]<1001){ pre[su[j]].pb(j); } /*for(int i=0;i<n;i++){ if(aa[i]==su[j]){ pre[i].pb(j); if(n==1){ ans="YES"; } } }*/ } /* if(n==1){ cout<<ans<<endl; return 0; }*/ for(int j=0;j<(1<<m);j++){ dp[n][j]=1; } vector<int> cur; cur.pb(0); for(int i=n-1;i>=0;i--){ vector<int> cur2; for(auto j:cur){ for(auto k:pre[aa[i]]){ if((k&j)==0){ if(dp[i][j+k]==0){ dp[i][j+k]=dp[i+1][j]; if(dp[i][j+k]){ if(i==0){ ans="YES"; } cur2.pb(j+k); } //cur2.pb(j+k); } /*if(dp[i][j+]){ break; }*/ } } /*for(int k=j;k>0;k=(k-1)&j){ if(su[k]==aa[i]){ } }*/ } cur=cur2; /*for(auto j:cur2){ cout<<i<<","<<j<<endl;; }*/ } cout<<ans<<endl; return 0; if(dp[0][(1<<m)-1]){ cout<<"YES"<<endl; } else{ cout<<"NO"<<endl; } 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...