# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
171934 | davitmarg | Bank (IZhO14_bank) | C++17 | 732 ms | 64364 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.
/*DavitMarg*/
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <cstring>
#include <map>
#include <unordered_map>
#include <set>
#include <queue>
#include <iomanip>
#include <bitset>
#include <stack>
#include <cassert>
#include <iterator>
#include <fstream>
#define mod 1000000007ll
#define LL long long
#define LD long double
#define MP make_pair
#define PB push_back
#define all(v) v.begin(), v.end()
using namespace std;
const int N = 25;
int n, m, dp[N][(1 << 20) + 5];
int a[N], b[N], sum[(1 << 20) + 5];
vector<int> masks[N * 1003];
int main()
{
cin >> n >> 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 < (1 << m); mask++)
{
for (int i = 0; i < m; i++)
if (((1 << i) & mask))
sum[mask] += b[i + 1];
masks[sum[mask]].PB(mask);
//cout << mask << " = " << sum[mask] << endl;
}
dp[0][0] = 1;
LL pr = 0;
for (int i = 1; i <= n; i++)
{
for (int j = 0; j < masks[a[i]].size(); j++)
{
int mask = masks[a[i]][j];
for (int x = 0; x < masks[pr].size(); x++)
{
int s = masks[pr][x];
if (dp[i - 1][s] && (mask & s) == 0)
dp[i][mask | s] = 1;
}
}
//for (int mask = 0; mask < (1 << m); mask++)
// cout << i << " : " << mask << " = " << dp[i][mask] << endl;
pr += a[i];
}
int ans = 0;
for (int mask = 0; mask < (1 << m); mask++)
ans += dp[n][mask];
if (ans)
cout << "YES" << endl;
else
cout << "NO" << endl;
return 0;
}
/*
2 4
9 10
5 4 5 5
000 0
001 1
010 2
011 3
100 4
101 5
110 6
111 7
*/
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... |