# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
393329 | asbsfds | Bank (IZhO14_bank) | C++14 | 642 ms | 62020 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 X first
#define Y second
using namespace std;
typedef long long llint;
const int maxn = 30;
const int base = 31337;
const int mod = 1e9+7;
const int inf = 0x3f3f3f3f;
const int logo = 20;
const int off = 1 << logo;
const int treesiz = off << 1;
int n, m;
int a[maxn], b[maxn];
bool dp[maxn][treesiz];
vector< int > v[maxn];
bool solve(int x, int mask) {
if (x == n) return true;
if (dp[x][mask]) return false;
dp[x][mask] = true;
bool out = false;
for (int i = 0; i < v[x].size(); i++) {
int tmask = v[x][i];
if ((mask & tmask) == 0) {
int nmask = mask | tmask;
out |= solve(x + 1, nmask);
}
}
return out;
}
int main() {
scanf("%d%d", &n, &m);
for (int i = 0; i < n; i++)
scanf("%d", a+i);
for (int i = 0; i < m; i++)
scanf("%d", b+i);
int lim = (1 << m);
for (int mask = 0; mask < lim; mask++) {
int sum = 0;
for (int i = 0; i < m; i++) {
if (mask & (1 << i)) sum += b[i];
}
for (int i = 0; i < n; i++) {
if (sum == a[i]) v[i].push_back(mask);
}
}
memset(dp, false, sizeof dp);
if (solve(0, 0)) printf("YES\n");
else printf("NO\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... |