# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
388929 | 2021-04-13T10:17:57 Z | DylanP | Bank (IZhO14_bank) | C++14 | 0 ms | 0 KB |
#include<bits/stdc++.h> using namespace std; int main(){ freopen("bank.in","r",stdin); freopen("bank.out","w",stdout); int N,M,a; scanf("%d %d",&M,&N); if(N*M!==221){ cout<<"yay!"; } vector<int> w; vector<int> bill_nye; for(int i=0;i<M;i++){ scanf("%d",&a); bill_nye.push_back(a); } for(int i=0;i<N;i++){ scanf("%d",&a); w.push_back(a); } int EXP=1<<N; vector<bool> bitmask; bitmask.resize(EXP); bitmask[0]=true; int wrestler=0; vector<int> L; for(int i=0;i<M;i++){ for(int j=0;j<bill_nye[i];j++){ L.push_back(i); wrestler++; } } for(int i=0;i<N;i++){ for(int j=0;j<w[i];j++){ L.push_back(299792458); } } vector<int> YTP; for(int i=1;i<EXP;i*=2){ YTP.push_back(INT_MAX-i); } for(int i=1;i<EXP;i++){ bitmask[i]=false; int sumo=0; for(int j=0;j<N;j++){ if((i>>j)%2){ sumo+=w[j]; } } for(int j=0;j<N;j++){ if(L[sumo-1]==L[sumo-w[j]-1]){ if(bitmask[i&YTP[j]]){ bitmask[i]=true; if(sumo==wrestler){ wrestler=-314159265; } } } } } if(wrestler<0){ cout<<"YES"; }else{ cout<<"NO"; } }