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;
int n,m;
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin>>n>>m;
vector<int>alln(n),allm(m);
vector<int>ps((1<<m)),dp((1<<m),1);
for(int i=0;i<n;i++){
cin>>alln[i];
}
for(int i=0;i<m;i++){
cin>>allm[i];
}
vector<int>dpp[n];
for(int i=1;i<(1<<m);i++){
for(int h=0;h<m;h++){
if((i>>h)&1){
ps[i]+=allm[h];
}
}
for(int h=0;h<n;h++){
if(ps[i]==alln[h]){
dpp[h].push_back(i);
}
}
}
int now=0;
for(int w=0;w<n;w++){
now+=alln[w];
for(int i=(1<<m)-1;i>=0;i--){
if(ps[i]!=now){
dp[i]=0;
continue;
}
int f=0;
for(auto x:dpp[w]){
if((x&i)==x){
if(dp[i^x]==1){
f=1;
break;
}
}
}
dp[i]=f;
}
}
int res=0;
for(int i=0;i<(1<<m);i++){
if(dp[i]==1){
res=1;
break;
}
}
if(res==1){
cout<<"YES"<<endl;
}else{
cout<<"NO"<<endl;
}
}
# | 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... |