# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
855110 | bestrazhuxp | 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>
#define ll long long
#define se second
#define fi first
#define pb push_back
#define all(x) (x).begin() , (x).end()
#define sz(x) (int)(x).size()
#define BIT(x , i) ((x) >> (i) & 1)
#define MASK(i) (1LL << (i))
#define name "1"
#define task ""
using namespace std;
const int inf = 1e9 + 7;
const ll linf = 1ll * inf * inf;
const int mod = 1e9 + 7;
const int maxn = 1e5 + 2;
vector <int> f[1 << 21];
int a[21];
int b[21];
vector <int> s[int(1e7)];
void file(){if(fopen(task".inp" , "r")){freopen(task".inp" , "r" , stdin);freopen(task".out" , "w" , stdout);}else if(fopen(name".inp" , "r")){freopen(name".inp" , "r" , stdin);freopen(name".out" , "w" , stdout);}}
int n , m;
int main()
{
file();
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> n >> m;
for(int i = 0; i < n; i++) cin >> a[i];
for(int i = 0 ; i < m; i++) cin >> b[i];
for(int i = 0 ; i < MASK(m) ; i++)
{
int sum = 0;
for(int j = 0 ; j < m ; j++) if(BIT(i , j)) sum += b[j];
s[sum].pb(i);
}
f[0].pb(0);
for(int mask = 1; mask < MASK(n) ; mask++)
{
for(int j = 0 ; j < n; j++)
{
if(BIT(mask , j))
int prev = mask ^ MASK(j);
for(auto x : f[prev])
{
for(auto y : s[a[j]])
{
if(!(x & y))
{
f[mask].pb(x ^ y);
}
}
}
}
}
if(sz(f[MASK(n) - 1]) == 0) return cout << "NO" , 0;
cout << "YES";
}