# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
566669 | racsosabe | Bank (IZhO14_bank) | C++14 | 1004 ms | 25160 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 MASK = 1 << 20;
const int N = 20;
int n;
int m;
int a[N];
int b[N];
int sum[MASK];
bool vis[N][MASK];
bool memo[N][MASK];
void preprocess(){
for(int mask = 1; mask < (1 << m); mask++){
sum[mask] = sum[mask & (mask - 1)] + b[__builtin_ctz(mask)];
}
}
bool DP(int pos, int mask){
if(pos == n) return true;
if(vis[pos][mask]) return memo[pos][mask];
bool ans = false;
for(int m = mask; m > 0; m = mask & (m - 1)){
if(sum[m] == a[pos] and DP(pos + 1, mask ^ m)){
ans = true;
break;
}
}
vis[pos][mask] = true;
return memo[pos][mask] = ans;
}
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);
sort(a, a + n);
preprocess();
puts(DP(0, (1 << m) - 1) ? "YES" : "NO");
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... |