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>
typedef long long ll;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
ll n,m,i,a[22],b[22];
vector<ll> isi[22];
void hai(ll aa,ll bb)
{
if(aa==(m+1))
{
if(bb==a[1])
{
cout<<"YES\n";
exit(0);
}
}
else
{
hai(aa+1,bb);
hai(aa+1,bb+b[aa]);
}
}
void cek(ll aa,ll bb,ll cc)
{
if(aa==(m+1))
{
if(bb==a[i])
{
isi[i].pb(cc);
}
}
else
{
cek(aa+1,bb,cc);
cek(aa+1,bb+b[aa],cc+(1<<(aa-1)));
}
}
int main()
{
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
cin>>n>>m;
for(i=1;i<=n;i++)cin>>a[i];
for(i=1;i<=m;i++)cin>>b[i];
if(1)
{
isi[0].pb(0);
for(i=1;i<=n;i++)
cek(1,0,0);
for(i=1;i<=n;i++)
{
vector<ll> tem;
ll ii,jj;
for(ii=0;ii<isi[i-1].size();ii++)
for(jj=0;jj<isi[i].size();jj++)
if(!(isi[i-1][ii]&isi[i][jj]))
tem.pb(isi[i-1][ii]|isi[i][jj]);
isi[i]=tem;
}
if(isi[n].empty())cout<<"NO\n";
else cout<<"YES\n";
}
else
{
hai(1,0);
cout<<"NO\n";
}
}
Compilation message (stderr)
bank.cpp: In function 'int main()':
bank.cpp:56:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(ii=0;ii<isi[i-1].size();ii++)
~~^~~~~~~~~~~~~~~~
bank.cpp:57:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(jj=0;jj<isi[i].size();jj++)
~~^~~~~~~~~~~~~~
# | 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... |