# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
935093 | ntdaccode | Bank (IZhO14_bank) | C++17 | 1030 ms | 44260 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,f[1<<20];
bool dd[21][1<<20],d[21][1<<20];
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,check=0;
fori(mask,1,(1<<m)-1)
{
fori(i,1,m)
{
if(mask&(1<<(i-1))) f[mask]+=b[i];
}
}
fori(i,1,n)
{
check=0;
sum+=a[i];
fori(mask,1,(1<<m)-1)
{
if(f[mask]>sum) continue;
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;
break;
}
}
}
if(f[mask]==sum&&OK)
{
dd[i][mask]=true;
check=1;
}
}
}
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... |