# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
848007 | _hbk06 | Bank (IZhO14_bank) | C++14 | 0 ms | 344 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;
const int mxN = 5e5 + 5;
#define int long long
#define MASK(n) (1 << (n))
#define BIT(mask,x) ((mask >> x) & 1)
const long long infll = 1e18 + 69;
int n;
int m;
int a[20];
int b[20];
int s[MASK(20)];
bool dp[MASK(20)][20];
signed main () {
freopen("bank.in","r",stdin);
freopen("bank.out","w",stdout);
cin >> n >> m;
for (int i = 1; i <= n; i++) cin >> a[i];
for (int i = 0; i < m; i++) cin >> b[i];
for (int mask = 0; mask < MASK(m); mask++)
for (int j = 0; j < m; j++) if(BIT(mask,j)) s[mask] += b[j];
dp[0][0] = 1;
for (int mask = 0; mask < MASK(m); mask++)
for (int sub = mask; sub; sub = (sub - 1) & mask)
for (int i = 1; i <= n; i++) {
if(s[sub] == a[i] && dp[mask ^ sub][i - 1]) dp[mask][i] = true;
}
bool kt = false;
for (int mask = 0; mask < MASK(m); mask++) if(dp[mask][n]) {kt = true;break;}
if(kt) cout << "YES" << "\n";
else 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... |