# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1087813 | quangminh412 | Bank (IZhO14_bank) | C++14 | 1075 ms | 41300 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;
/*
John Watson
https://codeforces.com/profile/quangminh98
Mua Code nhu mua Florentino !!
*/
#define faster() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
const int maxn = 30;
int n, m;
int a[maxn], b[maxn], s[1 << 21];
signed main()
{
if (fopen("test.inp", "r"))
{
freopen("test.inp", "r", stdin);
freopen("test.out", "w", stdout);
}
faster();
cin >> n >> m;
int full = (1 << m);
for (int i = 1; i <= n; i++) cin >> a[i];
for (int i = 1; i <= m; i++) cin >> b[i];
for (int mask = 0; mask < full; mask++)
{
int sum = 0;
for (int i = 0; i < m; i++)
if (mask >> i & 1)
sum += b[i + 1];
s[mask] = sum;
}
vector<vector<int>> dp(n + 5, vector<int>(full + 5, 0));
vector<int> pos[maxn];
// base case
for (int mask = 0; mask < full; mask++)
{
int sum = 0;
for (int i = 0; i < m; i++)
if (mask >> i & 1)
sum += b[i + 1];
if (sum == a[1])
{
dp[1][mask] = 1;
pos[1].push_back(mask);
}
}
//
for (int i = 2; i <= n; i++)
{
for (int mask1 : pos[i - 1])
{
for (int mask2 = 0; mask2 < full; mask2++)
if ((mask1 & mask2) == 0 && s[mask2] == a[i])
{
dp[i][mask1 | mask2] = 1;
pos[i].push_back(mask1 | mask2);
}
}
}
int ans = 0;
for (int mask = 0; mask < full; mask++)
ans = max(ans, dp[n][mask]);
cout << (ans == 0 ? "NO\n" : "YES\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... |