/**
* author: milos
* created: 22.03.2021 08:41:57
**/
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n, m;
cin >> n >> m;
vector<int> a(n);
vector<int> b(m);
for (int i = 0; i < n; i++) cin >> a[i];
for (int i = 0; i < m; i++) cin >> b[i];
const int MAX = 2e4 + 5;
vector<vector<int>> v(MAX);
for (int i = 0; i < (1 << m); i++) {
int sum = 0;
for (int j = 0; j < m; j++) {
if (i & (1 << j)) {
sum += b[j];
}
}
v[sum].push_back(i);
}
vector<int> masks;
masks.push_back(0);
vector<vector<bool>> was(n, vector<bool>((1 << m), false));
for (int i = 0; i < n; i++) {
vector<int> nm;
for (int j : v[a[i]]) {
for (int k : masks) {
if ((j ^ k) == (j | k) && !was[i][j ^ k]) {
nm.push_back(j ^ k);
was[i][j ^ k] = true;
}
}
}
swap(nm, masks);
}
cout << (masks.empty() ? "NO" : "YES") << '\n';
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
748 KB |
Output is correct |
2 |
Correct |
1 ms |
748 KB |
Output is correct |
3 |
Correct |
1 ms |
748 KB |
Output is correct |
4 |
Correct |
3 ms |
1004 KB |
Output is correct |
5 |
Correct |
76 ms |
7532 KB |
Output is correct |
6 |
Correct |
1 ms |
768 KB |
Output is correct |
7 |
Correct |
1 ms |
876 KB |
Output is correct |
8 |
Correct |
75 ms |
6636 KB |
Output is correct |
9 |
Correct |
75 ms |
7148 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
748 KB |
Output is correct |
2 |
Correct |
1 ms |
748 KB |
Output is correct |
3 |
Correct |
1 ms |
896 KB |
Output is correct |
4 |
Correct |
1 ms |
748 KB |
Output is correct |
5 |
Correct |
1 ms |
748 KB |
Output is correct |
6 |
Correct |
1 ms |
748 KB |
Output is correct |
7 |
Correct |
1 ms |
748 KB |
Output is correct |
8 |
Correct |
1 ms |
748 KB |
Output is correct |
9 |
Correct |
1 ms |
896 KB |
Output is correct |
10 |
Correct |
1 ms |
876 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
1004 KB |
Output is correct |
2 |
Correct |
2 ms |
1004 KB |
Output is correct |
3 |
Correct |
3 ms |
1004 KB |
Output is correct |
4 |
Correct |
2 ms |
1004 KB |
Output is correct |
5 |
Correct |
2 ms |
1004 KB |
Output is correct |
6 |
Correct |
3 ms |
1004 KB |
Output is correct |
7 |
Correct |
2 ms |
1004 KB |
Output is correct |
8 |
Correct |
3 ms |
896 KB |
Output is correct |
9 |
Correct |
3 ms |
1016 KB |
Output is correct |
10 |
Correct |
2 ms |
1004 KB |
Output is correct |
11 |
Correct |
2 ms |
876 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
748 KB |
Output is correct |
2 |
Correct |
1 ms |
748 KB |
Output is correct |
3 |
Correct |
1 ms |
748 KB |
Output is correct |
4 |
Correct |
3 ms |
1004 KB |
Output is correct |
5 |
Correct |
76 ms |
7532 KB |
Output is correct |
6 |
Correct |
1 ms |
768 KB |
Output is correct |
7 |
Correct |
1 ms |
876 KB |
Output is correct |
8 |
Correct |
75 ms |
6636 KB |
Output is correct |
9 |
Correct |
75 ms |
7148 KB |
Output is correct |
10 |
Correct |
1 ms |
748 KB |
Output is correct |
11 |
Correct |
1 ms |
748 KB |
Output is correct |
12 |
Correct |
1 ms |
896 KB |
Output is correct |
13 |
Correct |
1 ms |
748 KB |
Output is correct |
14 |
Correct |
1 ms |
748 KB |
Output is correct |
15 |
Correct |
1 ms |
748 KB |
Output is correct |
16 |
Correct |
1 ms |
748 KB |
Output is correct |
17 |
Correct |
1 ms |
748 KB |
Output is correct |
18 |
Correct |
1 ms |
896 KB |
Output is correct |
19 |
Correct |
1 ms |
876 KB |
Output is correct |
20 |
Correct |
2 ms |
1004 KB |
Output is correct |
21 |
Correct |
2 ms |
1004 KB |
Output is correct |
22 |
Correct |
3 ms |
1004 KB |
Output is correct |
23 |
Correct |
2 ms |
1004 KB |
Output is correct |
24 |
Correct |
2 ms |
1004 KB |
Output is correct |
25 |
Correct |
3 ms |
1004 KB |
Output is correct |
26 |
Correct |
2 ms |
1004 KB |
Output is correct |
27 |
Correct |
3 ms |
896 KB |
Output is correct |
28 |
Correct |
3 ms |
1016 KB |
Output is correct |
29 |
Correct |
2 ms |
1004 KB |
Output is correct |
30 |
Correct |
2 ms |
876 KB |
Output is correct |
31 |
Correct |
77 ms |
7660 KB |
Output is correct |
32 |
Correct |
141 ms |
7020 KB |
Output is correct |
33 |
Correct |
79 ms |
8172 KB |
Output is correct |
34 |
Correct |
83 ms |
8968 KB |
Output is correct |
35 |
Correct |
84 ms |
9964 KB |
Output is correct |
36 |
Correct |
88 ms |
10604 KB |
Output is correct |
37 |
Correct |
81 ms |
8556 KB |
Output is correct |
38 |
Correct |
80 ms |
8556 KB |
Output is correct |
39 |
Correct |
82 ms |
7872 KB |
Output is correct |
40 |
Correct |
81 ms |
9240 KB |
Output is correct |
41 |
Correct |
80 ms |
9964 KB |
Output is correct |
42 |
Correct |
79 ms |
7020 KB |
Output is correct |
43 |
Correct |
79 ms |
9324 KB |
Output is correct |
44 |
Correct |
85 ms |
10220 KB |
Output is correct |
45 |
Correct |
77 ms |
7404 KB |
Output is correct |
46 |
Correct |
78 ms |
9068 KB |
Output is correct |
47 |
Correct |
83 ms |
9708 KB |
Output is correct |
48 |
Correct |
74 ms |
6764 KB |
Output is correct |
49 |
Correct |
74 ms |
6892 KB |
Output is correct |
50 |
Correct |
121 ms |
9924 KB |
Output is correct |
51 |
Correct |
76 ms |
8172 KB |
Output is correct |
52 |
Correct |
79 ms |
6720 KB |
Output is correct |
53 |
Correct |
414 ms |
7604 KB |
Output is correct |
54 |
Correct |
139 ms |
9908 KB |
Output is correct |
55 |
Correct |
122 ms |
9924 KB |
Output is correct |
56 |
Correct |
115 ms |
10264 KB |
Output is correct |
57 |
Correct |
121 ms |
10276 KB |
Output is correct |
58 |
Correct |
122 ms |
10148 KB |
Output is correct |