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>
using namespace std;
#define ll long long
#define pb push_back
int main(){
int n,m;
cin>>n>>m;
int a[n+5],b[m+5];
for(int i=0;i<n;i++){
cin>>a[i];
}
for(int i=0;i<m;i++){
cin>>b[i];
}
vector<int>v[n+5];
for(int i=0;i<(1<<m);i++){
int cur=0;
for(int j=0;j<m;j++){
if((i&(1<<j))>0){
cur+=b[j];
}
}
for(int j=0;j<n;j++){
if(a[j]==cur){
v[j].pb(i);
}
}
}
for(int i=0;i<n;i++){
if(v[i].size()==0){
cout<<"NO";
return 0;
}
}
int dp[m+5][(1<<m)+5];
for(int i=0;i<m;i++){
fill(dp[i],dp[i]+(1<<m)+1,0);
}
for(auto x:v[0]){
dp[0][x]=1;
}
for(int i=1;i<n;i++){
for(int j=0;j<(1<<m);j++){
if(dp[i-1][j]==0){
continue;
}
for(auto x:v[i]){
if((x&j)==0){
dp[i][x+j]=1;
}
}
}
}
for(int i=0;i<(1<<m);i++){
if(dp[n-1][i]==1){
cout<<"YES";
return 0;
}
}
cout<<"NO";
}
# | 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... |