#include<unordered_map>
#include<unordered_set>
#include<algorithm>
#include<iostream>
#include<cstdlib>
#include<iomanip>
#include<cstring>
#include<cassert>
#include<numeric>
#include<vector>
#include<string>
#include<chrono>
#include<random>
#include<stack>
#include<queue>
#include<cmath>
#include<set>
#include<map>
#include<ios>
using namespace std;
int n, m, f = 0;
vector<bool>vs(2e6);
vector<int>a, b;
vector<vector<int>>gp;
bool dfs(int id, int vis) {
if (id == n) {
return 1;
}
vs[vis] = true;
for (int& x : gp[a[id]]) {
if ((vis ^ x) == (vis | x) && !vs[vis | x]) {
if (dfs(id + 1, vis | x)) return true;
//if (f) return;
}
}
}
void solve()
{
cin >> n >> m;
a = vector<int>(n);
b = vector<int>(m);
gp = vector<vector<int>>(2e5 + 1);
for (int i = 0; i < n; i++) cin >> a[i];
for (int j = 0; j < m; j++) cin >> b[j];
for (int i = 0; i < (1 << m); i++) {
int sum = 0;
for (int j = 0; j < m; j++) {
if ((1 << j) & i) sum += b[j];
}
gp[sum].push_back(i);
}
//dfs(0, 0);
cout << (dfs(0,0) ? "YES" : "NO");
}
signed main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
//freopen("bank.in", "r", stdin);
//freopen("bank.out", "w", stdout);
//signed _; cin >> _; while (_--)
solve();
}
컴파일 시 표준 에러 (stderr) 메시지
bank.cpp: In function 'bool dfs(int, int)':
bank.cpp:36:1: warning: control reaches end of non-void function [-Wreturn-type]
36 | }
| ^| # | 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... |