# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
935087 | ntdaccode | Bank (IZhO14_bank) | C++17 | 1055 ms | 22100 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>
#define fori(i,a,b) for(int i=a;i<=b;i++)
#define ll long long
#define ii pair<int,int>
#define fi first
#define se second
#define pb push_back
using namespace std;
const int mod=1e9+7;
const int M=1e6+10;
const int N=1e3+10;
int n,a[21],b[21],m;
bool dd[21][1<<20],d[21][1<<20];
bool check()
{
fori(i,1,(1<<m)-1)
{
if(dd[n][i]) return true;
}
return false;
}
int32_t main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
if(fopen("1.inp","r"))
{
freopen("1.inp","r",stdin);
freopen("1.out","w",stdout);
}
if(fopen("bank.inp","r"))
{
freopen("bank.inp","r",stdin);
freopen("bank.out","w",stdout);
}
cin >> n >> m;
fori(i,1,n) cin >> a[i];
fori(i,1,m) cin >> b[i];
dd[0][0]=true;
int sum=0;
fori(i,1,n)
{
sum+=a[i];
fori(mask,1,(1<<m)-1)
{
//cout << mask << "\n";
int res=0;
bool OK=0;
fori(j,1,m)
{
if(mask&(1<<(j-1)))
{
int bit=mask^(1<<(j-1));
if(dd[i-1][bit]||d[i][bit])
{
d[i][mask]=true;
OK=1;
}
res+=b[j];
}
}
//cout << res << " " << sum << " " << OK << "\n";
if(res==sum&&OK) dd[i][mask]=true;
}
}
if(check()) 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... |