# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
96224 | Kastanda | Bank (IZhO14_bank) | C++11 | 69 ms | 4572 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 N = 20, MXN = (1 << N) + 5;
int n, m, A[N], B[N], sum[MXN];
vector < int > vec[N];
multiset < int > SS;
void Go(int mask, int i)
{
if (i == n)
{
printf("YES\n");
exit(0);
}
for (int mask2 : vec[i])
if ((mask & mask2) == 0)
Go(mask ^ mask2, i + 1);
}
int main()
{
scanf("%d%d", &n, &m);
for (int i = 0; i < n; i++)
scanf("%d", &A[i]), SS.insert(A[i]);
for (int i = 0; i < m; i++)
{
scanf("%d", &B[i]);
if (SS.count(B[i]))
SS.erase(SS.lower_bound(B[i])), i --, m --;
}
n = 0;
for (int a : SS)
A[n ++] = a;
if (n + n > m)
return !printf("NO\n");
for (int i = 1; i < (1 << m); i++)
{
sum[i] = sum[i ^ (1 << __builtin_ctz(i))] + B[__builtin_ctz(i)];
for (int j = 0; j < n; j++)
if (sum[i] == A[j])
vec[j].push_back(i);
}
Go(0, 0);
return !printf("NO\n");
}
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... |