# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
725879 | AndrijaM | Bank (IZhO14_bank) | C++14 | 75 ms | 296 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;
int n,m;
int x[20];
int y[20];
int dp[23];
bool f(int idx,int mask)
{
if(idx==n)
{
return 1;
}
if(__builtin_popcount(mask)==m)
{
return 0;
}
if(dp[idx]!=-1)return dp[idx];
int rez=0;
for(int i=0;i<(1<<m);i++)
{
int sum=0;
if(i&mask)
{
}
else
{
for(int bit=0;bit<=23;bit++)
{
if(i&(1<<bit))
{
sum+=y[bit];
}
}
if(sum==x[idx])
{
int bmask=mask;
bmask|=i;
rez|=f(idx+1,bmask);
}
}
}
return dp[idx]=rez;
}
int main()
{
ios::sync_with_stdio(0);
memset(dp,-1,sizeof dp);
cin>>n>>m;
for(int i=0;i<n;i++)cin>>x[i];
for(int i=0;i<m;i++)cin>>y[i];
if(f(0,0))
{
cout<<"YES"<<endl;
return 0;
}
cout<<"NO"<<endl;
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... |