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'
#define fi first
#define sc second
//#define int ll
#define pii pair<int, int>
#define all(v) v.begin(), v.end()
using namespace std;
using ll=long long;
using ull=unsigned long long;
using ld=long double;
const int mod=1e9+7;
const int N=1e5+11;
int n, m, a[24], b[24], dp[24][1<<21];
vector<int> ss[N];
void dpp(int id, int mask)
{
if(id==n+1)
{
cout << "YES";
exit(0);
}
if(dp[id][mask]) return;
dp[id][mask]=1;
for(int ms:ss[a[id]]) if((ms&mask)==0) dpp(id+1, mask|ms);
}
void sol()
{
cin >> n >> m;
for(int i=1;i<=n;i++) cin >> a[i];
for(int i=1;i<=m;i++) cin >> b[i];
for(int mask=1;mask<(1<<m);mask++)
{
int sum=0;
for(int j=0;j<m;j++) if(mask>>j&1) sum+=b[j+1];
ss[sum].push_back(mask);
}
dpp(1, 0);
cout << "NO";
}
signed main()
{
// freopen("divisor.INP", "r", stdin);
// freopen("divisor.OUT", "w", stdout);
ios_base::sync_with_stdio(0);
cin.tie(0);
int t=1;
//cin >> t;
while(t--)
{
sol();
}
}
# | 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... |