Submission #68559

#TimeUsernameProblemLanguageResultExecution timeMemory
68559quoriessBank (IZhO14_bank)C++14
100 / 100
496 ms23296 KiB
#include <bits/stdc++.h> using namespace std; typedef long long int lli; int main(){ int n,m; cin>>n>>m; vector<int> salary,banks; for (int i = 0; i < n; i++) { int a; cin>>a; salary.push_back(a); } for (int j = 0; j < m; j++) { int a; cin>>a; banks.push_back(a); } /* 2 4 3 6 5 1 2 1 */ vector<vector<bitset<20> > > sncler(n,vector<bitset<20> >()); for (int i = 0; i < 1<<m; i++) { bitset<20> smd(i); int tplm=0; for (int j = 0; j < m; j++) { if(smd[j]) tplm+=banks[j]; } for(int j=0;j<n;j++){ if(salary[j]==tplm) sncler[j].push_back(smd); } } int mstb=1<<m; bool dp[n][mstb]; vector<int> bakilacaklar; for(int i=0;i<n;i++){ for(int j=0;j<mstb;j++)dp[i][j]=0; } for(auto j:sncler[0]){ dp[0][j.to_ulong()]=1; bakilacaklar.push_back(j.to_ulong()); } for (int i = 1; i < n; i++) { vector<int> nb; for(auto k:bakilacaklar){ for (auto j: sncler[i]) { if((k&j.to_ulong())==0){ bool b=dp[i][k^j.to_ulong()]; dp[i][k^j.to_ulong()]=dp[i-1][k]||dp[i][k^j.to_ulong()]; if(b!=dp[i][k^j.to_ulong()])nb.push_back(k^j.to_ulong()); } } } swap(bakilacaklar,nb); } bool ans=0; for(int i=1;i<mstb;i++)if(dp[n-1][i])ans=true; cout << (ans?"YES":"NO")<<"\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...