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>
#define el '\n'
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
using namespace std ;
mt19937 rd(chrono::steady_clock::now().time_since_epoch().count());
int a[22] , b[22] , n , m;
namespace sub_final{
void solve(){
vector<vector<int>> pre_mask(n);
for ( int i = 0 ; i < n ; i++ ){
for ( int mask = 0 ; mask < (1 << m) ; mask++ ){
int sum = 0;
for ( int j = 0 ; j < m ; j++ ) sum += ((mask >> j & 1) ? b[j] : 0);
if (sum == a[i]) pre_mask[i].push_back(mask);
}
}
unordered_set<int> store;
bool satis = true;
for ( int i = 0 ; i < n ; i++ ){
if (i == 0){
for ( auto x : pre_mask[i] ) store.insert(x);
if (store.empty()){
satis = false;
break;
}
continue;
}
if (store.empty()){
satis = false;
break;
}
unordered_set<int> cur;
for ( auto j : store ){
for ( auto mask : pre_mask[i] ){
if (mask & j) continue;
else cur.insert(j | mask);
}
}
if (cur.empty()){
satis = false;
break;
}
swap(store , cur);
}
cout << (satis ? "YES" : "NO");
}
}
int32_t main (){
ios_base::sync_with_stdio(0);
cin.tie(0);
// freopen("izho_bank.inp" , "r" , stdin);
// freopen("izho_bank.out" , "w" , stdout);
cin >> n >> m;
for ( int i = 0 ; i < n ; i++ ) cin >> a[i];
for ( int i = 0 ; i < m ; i++ ) cin >> b[i];
sub_final::solve();
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |