# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1033433 | bytecode_1234 | Bank (IZhO14_bank) | C++14 | 2 ms | 604 KiB |
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;
using ll=long long;
int main()
{
#ifndef ONLINE_JUDGE
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
#endif
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll n,m;
cin>>n>>m;
vector<ll> v(n);
for(ll i=0;i<n;i++)
{
cin>>v[i];
}
vector<ll> v1(m);
for(ll i=0;i<m;i++)
{
cin>>v1[i];
}
vector<vector<ll>> dp1(n);
ll f=0;
for(ll i=0;i<n;i++)
{
for(ll j=0;j<=pow(2,m);j++)
{
ll sum=0;
for(ll k=0;k<m;k++)
{
if(j&(1<<k))
{
sum+=v1[k];
}
}
if(sum==v[i])
{
dp1[i].push_back(j);
}
}
if(dp1[i].size()==0)
{
f=1;
break;
}
}
if(f)
{
cout<<"NO"<<"\n";
}
else if(n==1)
{
if(dp1.size()>0)
{
cout<<"YES"<<"\n";
}
else
{
cout<<"NO"<<"\n";
}
}
else
{
vector<vector<ll>> dp(n+1,vector<ll>(pow(2,m),-1));
for(ll i=0;i<pow(2,m);i++)
{
dp[0][i]=0;
}
for(ll i=1;i<=n;i++)
{
for(ll j=0;j<pow(2,m);j++)
{
for(ll k=0;k<dp1[i-1].size();k++)
{
if((j&dp1[i-1][k])==dp1[i-1][k])
{
if(dp[i-1][j^(dp1[i-1][k])]==0)
{
dp[i][j]=0;
break;
}
}
}
}
}
if(dp[n][pow(2,m)-1]==0)
{
cout<<"YES"<<"\n";
}
else
{
cout<<"NO"<<"\n";
}
}
}
Compilation message (stderr)
# | 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... |