Submission #770936

#TimeUsernameProblemLanguageResultExecution timeMemory
770936matei__bBank (IZhO14_bank)C++14
71 / 100
1072 ms1308 KiB
#include <bits/stdc++.h> #define ll long long #define mod 1000000007 #define dim 100002 #define lim 1000000 #define mdim 1501 #define mult 2e9 #define maxx 200000 #define simaimult 1e17 #define piii pair<int,pair<int,int> > #define pii pair<int,int> #define pb push_back #define mp make_pair #define nr_biti __builtin_popcount using namespace std; ifstream fin("b.in"); ofstream fout("b.out"); int n,m; int a[22],b[22]; bool dp[1<<22][22]; vector<int> curr; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); cin >> n >> m; for(int i=1; i<=n; i++) cin >> a[i]; for(int i=0; i<m; i++) cin >> b[i]; for(int i=1; i<=n; i++) { if(i==1) { bool ok=0; for(int j=1; j<(1<<m); j++) { int s=0; for(int z=0; z<m; z++) { if(j&(1<<z)) { s+=b[z]; } } if(s==a[1]) { if(!(m-nr_biti(j)<n-i)) { curr.pb(j); ok=1; } } } if(!ok) { cout <<"NO"; return 0; } } else { vector<int> temp; for(int j=1; j<(1<<m); j++) { int s=0; for(int z=0; z<m; z++) { if(j&(1<<z)) { s+=b[z]; } } if(s==a[i]) { for(auto it:curr) { bool okk=1; for(int z=0; z<m; z++) { if(it&(1<<z) && j&(1<<z)) okk=0; } if(okk) { if(!(m-nr_biti(j|it)<n-i)) temp.pb(j|it); } } } } curr=temp; if(curr.empty()) { cout <<"NO"; return 0; } } } cout << "YES"; 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...