# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
90726 | daniel_02 | Bank (IZhO14_bank) | C++17 | 1084 ms | 3804 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 fr first
#define pb push_back
#define sc second
#define ll long long
using namespace std;
const int N = 23;
int a[N], b[N];
bool dp[N][(1 << 20) + 7];
vector<int>v;
vector<int>vec;
vector<int>vecnew;
main()
{
int n, m, x;
cin >> n >> m;
for (int i = 1; i <= n; i++)
{
scanf("%d", &a[i]);
}
for (int i = 1; i <= m; i++)
{
scanf("%d", &b[i]);
}
for (int msk = 1; msk < (1 << m); msk++)
{
int sm = 0;
for (int i = 0; i < m; i++)
{
if (msk & (1 << i))
{
sm += b[i + 1];
}
}
if (sm == a[1])
{
dp[1][msk] = 1;
vecnew.pb(msk);
}
}
vec = vecnew;
vecnew.clear();
for (int i = 2; i <= n; i++)
{
for (int msk : vec)
{
for (int j = 0; j < m; j++)
{
if (!(msk & (1 << j)))
{
v.pb(j + 1);
}
}
int sz = v.size();
for (int msk1 = 1; msk1 < (1 << sz); msk1++)
{
int sm = 0;
for (int j = 0; j < sz; j++)
{
if (msk1 & (1 << j))
{
sm += b[v[j]];
}
}
if (sm == a[i])
{
int tmp = msk;
for (int j = 0; j < sz; j++)
{
if (msk1 & (1 << j))
{
tmp = (tmp | (1 << (v[j] - 1)));
}
}
dp[i][tmp] = 1;
vecnew.pb(tmp);
}
}
v.clear();
}
vec.clear();
vec = vecnew;
vecnew.clear();
}
for (int msk = 1; msk < (1 << m); msk++)
{
if (dp[n][msk])
{
puts("YES");
return 0;
}
}
puts("NO");
}
/*
4 20
5 5 5 5
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
*/
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... |