# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
570661 | YouAreMyGalaxy | Bank (IZhO14_bank) | C++17 | 614 ms | 4428 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.
//Make CSP great again
//Vengeance
#include <bits/stdc++.h>
#define TASK "TESTCODE"
#define Log2(x) 31 - __builtin_clz(x)
using namespace std;
const int N = 20;
int dp[1 << N];
int a[N], b[N], n, m;
void read()
{
cin >> n >> m;
for (int i = 0; i < n; ++ i)
{
cin >> a[i];
}
for (int i = 0; i < m; ++ i)
{
cin >> b[i];
}
}
void solve()
{
memset(dp, -1, sizeof(dp));
dp[0] = 0;
for (int i = 0; i < n; ++ i)
{
for (int mask = 0; mask < (1 << m); ++ mask)
{
if (dp[mask] != -1)
{
for (int j = 0; j < m; ++ j)
{
if (((mask >> j) & 1) == 0)
{
dp[mask | (1 << j)] = dp[mask] + b[j];
}
}
}
}
for (int mask = 0; mask < (1 << m); ++ mask)
{
if (dp[mask] == a[i])
{
dp[mask] = 0;
}
else
{
dp[mask] = -1;
}
}
}
for (int mask = 0; mask < (1 << m); ++ mask)
{
if (dp[mask] == 0)
{
cout << "YES";
return ;
}
}
cout << "NO";
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
if (fopen(TASK".INP", "r"))
{
freopen(TASK".INP", "r", stdin);
//freopen(TASK".OUT", "w", stdout);
}
int t = 1;
bool typetest = false;
if (typetest)
{
cin >> t;
}
for (int __ = 1; __ <= t; ++ __)
{
//cout << "Case " << __ << ": ";
read();
solve();
}
}
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... |