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 f first
#define s second
#define pb push_back
typedef long long ll;
#define pii pair<int,int>
using namespace std;
int n,m;
vector<int> lef,rig;
vector<int> mask_list[1001];
bitset<1001> jest;
bitset<1100000> curr;
void evaluate(int mask){
int wyn=0;
for(int i=0;i<m;i++)if((mask&(1<<i)))wyn+=rig[i];
if(wyn>1000||jest[wyn]==0)return;
mask_list[wyn].pb(mask);
}
void proc(int ind){
bitset<1100000> nex={false};
for(int i=0;i<(1<<m);i++){
if(!curr[i])continue;
for(int j : mask_list[lef[ind]])
if(!(i&j))nex[(i|j)]=1;
}
curr=nex;
}
int main()
{
cin>>n>>m;
lef.resize(n);
rig.resize(m);
for(int &i:lef){cin>>i; jest[i]=1;}
for(int &i:rig)cin>>i;
for(int i=0;i<(1<<m);i++)evaluate(i);
for(int i : mask_list[lef[0]])curr[i]=1;
if(curr.count()==0){cout<<"NO"; return 0;}
for(int i=1;i<n;i++){
proc(i);
if(curr.count()==0){cout<<"NO"; return 0;}
}
cout<<"YES";
return 0;
}
# | 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... |