Submission #358540

#TimeUsernameProblemLanguageResultExecution timeMemory
358540nicolaalexandraBank (IZhO14_bank)C++14
71 / 100
1084 ms512 KiB
#include <bits/stdc++.h> using namespace std; short v[22],a[22]; vector <int> L[22]; int n,m,i,sol; void back (int pas, int mask){ if (sol) return; if (pas > n){ sol = 1; return; } for (auto it : L[pas]){ if ( (it & mask) == 0) back (pas+1,mask | it); } } int main (){ //ifstream cin ("date.in"); //ofstream cout ("date.out"); cin>>n>>m; for (i=1;i<=n;++i) cin>>v[i]; for (i=0;i<m;++i) cin>>a[i]; int maxi = (1<<m); for (int mask=0;mask<maxi;++mask){ int sum = 0; for (int bit=0;bit<m;++bit){ if (mask & (1<<bit)) sum += a[bit]; } for (i=1;i<=n;++i){ if (v[i] == sum) L[i].push_back(mask); } } for (i=1;i<=n;++i) if (L[i].empty()){ cout<<"NO\n"; return 0; } back (1,0); if (sol) 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...