# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1115620 | tudor_costin | Bank (IZhO14_bank) | C++11 | 84 ms | 25416 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;
#define int long long
const int Nmax=1005;
vector<int> v[20*Nmax];
int dp[25][(1<<21)];
int sum[1<<21];
int a[25],b[25];
signed main()
{
int n,m;
cin>>n>>m;
for(int i=1;i<=n;i++) cin>>a[i];
for(int j=1;j<=m;j++) cin>>b[j];
for(int mask=0;mask<(1<<m);mask++)
{
for(int i=0;i<m;i++)
{
if((mask&(1<<i))!=0)
{
sum[mask]+=b[i];
}
}
v[sum[mask]].push_back(mask);
}
int S=0;
dp[0][0]=1;
for(int i=0;i<n;i++)
{
for(int mask=0;mask<(1<<m);mask++)
{
if(dp[i][mask]==1)
{
for(int u:v[a[i+1]])
{
if((u&mask)==0)
{
dp[i+1][(mask|u)]=1;
if(i+1==n)
{
cout<<"YES"<<'\n';
return 0;
}
}
}
}
}
}
cout<<"NO"<<'\n';
return 0;
}
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... |