# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
566657 | racsosabe | Bank (IZhO14_bank) | C++14 | 1035 ms | 72188 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 + 5;
const int MASK = 1 << 20;
int n;
int m;
int neg;
int a[N];
int b[N];
int total;
int sum[MASK];
bool vis[N][MASK];
int memo[N][MASK];
void preprocess(){
for(int mask = 1, l = 1 << m; mask < l; mask++) sum[mask] = sum[mask & (mask - 1)] + b[__builtin_ctz(mask)];
}
int DP(int pos, int mask){
if(pos == n) return 0;
if(vis[pos][mask]) return memo[pos][mask];
int ans = 0;
for(int m = mask ^ total; m > 0; m &= m - 1){
int to = __builtin_ctz(m);
int p = m & (-m);
int new_mask = mask | p;
if(sum[new_mask] == a[pos]) ans = max(ans, 1 + DP(pos + 1, new_mask));
else ans = max(ans, DP(pos, new_mask));
}
vis[pos][mask] = true;
return memo[pos][mask] = ans;
}
bool solve(){
return DP(0, 0) == n;
}
int main(){
scanf("%d %d", &n, &m);
total = (1 << m) - 1;
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);
for(int i = 1; i < n; i++) a[i] += a[i - 1];
preprocess();
puts(solve() ? "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... |