# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
566661 | racsosabe | Bank (IZhO14_bank) | C++14 | 267 ms | 10444 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 MAX = 1000 * 20 + 5;
const int MASK = 1 << 20;
int n;
int m;
int a[N];
int b[N];
int nxt[MAX];
int sum[MASK];
int memo[MASK];
bool vis[MASK];
set<int> used;
void preprocess(){
for(int i = 0; i < n; i++) used.emplace(a[i]);
for(int mask = 1; mask < 1 << m; mask++){
sum[mask] = sum[mask & (mask - 1)] + b[__builtin_ctz(mask)];
}
}
bool solve(){
queue<int> Q;
Q.emplace(0);
while(!Q.empty()){
int mask = Q.front(); Q.pop();
for(int i = 0, p = 1; i < m; i++, p <<= 1){
if(mask & p) continue;
int new_sum = sum[mask] + b[i];
if(used.count(new_sum)) memo[mask | p] = max(memo[mask | p], 1 + memo[mask]);
else memo[mask | p] = max(memo[mask | p], memo[mask]);
if(not vis[mask | p]){
vis[mask | p] = true;
Q.emplace(mask | p);
}
}
}
return *max_element(memo, memo + (1 << m)) == n;
}
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);
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... |