# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
80907 | farukkastamonuda | Bank (IZhO14_bank) | C++14 | 196 ms | 18812 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 fi first
#define se second
#define lo long long
#define inf 1000000000
#define md 1000000007
#define li 2005
#define mpt make_pair
#define pb push_back
using namespace std;
int n, m, A[22], B[22], sum[(1 << 20) + 5];
vector<int> v[22];
bool dp[22][(1 << 20) + 5];
void solve(int node, int msk){
if(node == n + 1){
printf("YES\n");
exit(0);
}
if(dp[node][msk] == true) return ;
dp[node][msk]=true;
for(int i = 0; i < (int)v[node].size(); i ++){
if(! (msk & v[node][i]) ) solve(node + 1, msk | v[node][i]);
}
}
int main(){
scanf("%d %d", &n, &m);
for(int i = 1; i <= n; i ++){
scanf("%d", &A[i]);
}
for(int i = 1; i <= m; i ++){
scanf("%d", &B[i]);
}
for(int i = 1; i < (1 << m) ; i ++){
for(int j = 0; j < m; j ++){
if(i&(1 << j)){
sum[i] = sum[i - (1 << j)] + B[j + 1];
break;
}
}
}
for(int i = 1; i <= n; i ++){
for(int j = 0; j < (1 << m) ; j ++){
if(A[i] == sum[j]){
v[i].pb(j);
}
}
}
solve(1, 0);
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... |