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<<20];
vector<int> ms, ss[24];
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 i=1;i<=n;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];
if(sum==a[i]) ss[i].push_back(mask);
}
}
ms.push_back(0);
dp[0][0]=1;
for(int id=1;id<=n;id++)
{
vector<int> new_mask;
for(int mask:ms)
{
for(int vl:ss[id])
{
if((vl&mask)==0) dp[id][mask|vl]=1, new_mask.push_back(mask|vl);
}
}
ms=new_mask;
}
int ch=0;
for(int i=0;i<(1<<m);i++) if(dp[n][i]) ch=1;
if(ch==1) cout << "YES";
else 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... |