# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1107258 | vjudge1 | Bank (IZhO14_bank) | C++17 | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
int n , T , q , m ;
signed main(){
ios_base::sync_with_stdio(0) , cin.tie(0);
cin>> n >> m ;
int a[n+1] , b[m] , ok =0 ;
for(int i= 1 ; i <= n ;i++)cin>> a[i];
for(int i =0 ; i < m; i++)cin>> b[i];
vector<vector<int>>mp[20000];
for(int j = 0 ; j < (1 << m )- 1; j++){
int x =0 ;
vector<int>v;
for(int u =0 ; u < m ; u++){
if((j >> u )&1){
x+=b[u];
v.pb(b[u]);
}
}
mp[x].pb(v);
}
queue<pair<int , unordered_map<int, int >>>q;
unordered_map<int ,int >h;
for(int i =0 ; i < m ; i++){
h[b[i]]++;
}
q.push({1 , h });
while(q.size()){
pair<int , unordered_map<int , int >> p= q.front();
q.pop();
int v = p.first ;
unordered_map<int ,int >us = p.second;
for(auto it:mp[a[v]]){
int ko =0 ;
for(auto at:it){
if(us[at])ko++;
us[at]--;
}
if(ko== it.size()){
if(v == n ){
cout << "YES";
return 0 ;
}
q.push({v + 1 ,us});
}
for(auto at:it){
us[at]++;
}
}
}
cout << "NO";
}