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 ff first
#define ss second
#define pb push_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
using namespace std;
const int N = 2e6;
vector <int> g[N];
int n, vis[25][N];
void rec(int pos, int v){
if(pos == n + 1){
cout <<"YES";
exit(0);
}
vis[pos][v] = 1;
for(auto to : g[pos]){
if((v & to) == 0 && !vis[pos + 1][(v ^ to)])
rec(pos + 1, (v ^ to));
}
}
main(){
int m;
cin >> n >> m;
vector <int> v(n + 1), a(m + 1);
for(int i = 1; i <= n; i++){
cin >> v[i];
}
for(int i = 1; i <= m; i++){
cin >> a[i];
}
for(int i = 1; i < (1 << m); i++){
int sum = 0;
for(int j = 0; j < m; j++)
if(i & (1 << j)){
sum += a[j + 1];
}
//cout << sum << endl;
for(int j = 1; j <= n; j++){
if(v[j] == sum)g[j].pb(i);
}
}
rec(1, 0);
cout << "NO";
}
Compilation message (stderr)
bank.cpp:24:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
24 | main(){
| ^~~~
# | 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... |