#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
//#pragma GCC target("avx,avx2,fma")
//#pragma GCC optimize("Ofast,unroll-loops")
using namespace std;
using namespace __gnu_pbds;
#define pb push_back
#define all(x) x.begin(),x.end()
#define int long long
// #define double long double
#define ar array
#define mrand(a, b) uniform_int_distribution<int>(a, b)(rng)
template<class T>bool umax(T &a,T b){if(a<b){a=b;return true;}return false;}
template<class T>bool umin(T &a,T b){if(b<a){a=b;return true;}return false;}
template<class T> using ste = tree<T, null_type, less_equal<T>,
rb_tree_tag, tree_order_statistics_node_update>;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
int binpow(int a, int b, int m){
if(b <= 0)return 1;
if(b % 2 == 0){
int c = binpow(a,b/2,m);
return (c*c)%m;
}
return (binpow(a,b-1,m)*a)%m;
}
int divi(int a, int b, int m){
return (a*(binpow(b,m-2, m)))%m;
}
struct modint {
static int mod;
long long val;
modint(long long v = 0) {
val = v % mod;
if (val < 0) val += mod;
}
modint& operator+=(const modint& other) {
val += other.val;
if (val >= mod) val -= mod;
return *this;
}
modint& operator+=(long long other) {
return *this += modint(other);
}
modint& operator-=(const modint& other) {
val -= other.val;
if (val < 0) val += mod;
return *this;
}
modint& operator-=(long long other) {
return *this -= modint(other);
}
modint& operator*=(const modint& other) {
val = (val * other.val) % mod;
return *this;
}
modint& operator*=(long long other) {
return *this *= modint(other);
}
modint& operator/=(const modint& other) {
val = divi(val, other.val, mod);
return *this;
}
modint& operator/=(long long other) {
return *this /= modint(other);
}
friend modint operator+(modint a, const modint& b) { return a += b; }
friend modint operator+(modint a, long long b) { return a += b; }
friend modint operator+(long long a, modint b) { return b += a; }
friend modint operator-(modint a, const modint& b) { return a -= b; }
friend modint operator-(modint a, long long b) { return a -= b; }
friend modint operator-(long long a, modint b) { return modint(a) -= b; }
friend modint operator*(modint a, const modint& b) { return a *= b; }
friend modint operator*(modint a, long long b) { return a *= b; }
friend modint operator*(long long a, modint b) { return b *= a; }
friend modint operator/(modint a, const modint& b) { return a /= b; }
friend modint operator/(modint a, long long b) { return a /= b; }
friend modint operator/(long long a, modint b) { return modint(a) /= b; }
friend ostream& operator<<(ostream& os, const modint& m) {
return os << m.val;
}
};
int modint::mod = 1e9 + 7;
namespace FAST {
template<typename T>
istream &operator>>(istream &cin, vector<T> &a) {
for (T &i: a) cin >> i;
return cin;
}
template<typename T>
ostream &operator<<(ostream &cout, vector<T> &a) {
for (T i: a) cout << i << ' ';
return cout;
}
}
using namespace FAST;
const int inf = 3e18 + 7;
const int mod = 1e9 + 7;
const int N = 6e5 + 5;
const int md = 998244353;
int rev(int a, int m){
if (a == 1)return 1;
return (1 - rev(m % a, a) * m) / a + m;
}
struct Bit {
vector<int> b, b2;
int n;
Bit(int n) {
this->n = n + 1;
b.assign(n + 1, 0);
b2.assign(n+1, 0);
}
void add(vector<int>&b, int idx, int x){
while(idx <= n){
b[idx] += x;
idx += idx & -idx;
}
}
void upd(int l, int r, int x){
add(b, l, x);
add(b, r+1, -x);
add(b2, l, x*(l-1));
add(b2, r+1, -x*r);
}
int sum(vector<int>&b, int idx){
int res = 0;
while(idx > 0){
res += b[idx];
idx -= idx & -idx;
}
return res;
}
int pref(int idx){
return sum(b, idx) * idx - sum(b2, idx);
}
int get(int l, int r){
return pref(r) - pref(l-1);
}
};
int n,m,k;
int vis[(1 << 20)][20];
vector<int>dp[1005];
vector<int>a;
void dfs(int mask, int ind){
if(ind == n){
cout << "YES\n";
exit(0);
}
if(vis[mask][ind])return;
vis[mask][ind] = 1;
for(auto mk : dp[a[ind]]){
bool flag = false;
for(int i = 0;i<m;i++){
if((mask >> i & 1) == 1 && (mk >> i & 1) == 1){
flag = true;
break;
}
}
if(flag)continue;
dfs((mask | mk), ind + 1);
}
}
void solve(){
cin >> n >> m;
for(int i = 0;i<n;i++){
cin >> k;
a.pb(k);
}
vector<int>b(m);
cin >> b;
for(int mask = 1;mask<(1 << m);mask++){
int sum = 0;
for(int i = 0;i<m;i++){
sum += (mask >> i & 1) * b[i];
}
dp[sum].pb(mask);
}
dfs(0, 0);
cout << "NO\n";
}
/*
*/
signed main()
{
// freopen("seq.in", "r", stdin);
// freopen("seq.out", "w", stdout);
ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
int tt=1;//cin >> tt;
while(tt--)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... |