#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> pi;
#define f first
#define s second
#define FAST ios_base::sync_with_stdio(0); cin.tie(0);
#define all(x) x.begin(),x.end()
typedef pair<int, pi> pii;
const int maxn = 100;
const int INF = LLONG_MAX/2;
int n,m;
int A[maxn];
int B[maxn];
pi dp[(1 << 20)];
int32_t main() {
FAST
cin >> n >> m;
for (int i =0;i<n;i++) cin >> A[i];
for (int i =0;i<m;i++) cin >> B[i];
for (int bm = 0; bm < (1 << m); bm++) {
for (int i =0;i<m;i++) {
if (((1 << i) & bm) == 0) continue;
int prevbm = bm ^ (1 << i);
auto [x, sum] = dp[prevbm];
if (sum + B[i] == A[x]) {
dp[bm] = max(dp[bm], pi(x + 1, 0));
} else {
dp[bm] = max(dp[bm], pi(x, sum + B[i]));
}
}
}
if (dp[(1<<m)-1].f == n) cout << "YES";
else cout << "NO";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
3 ms |
836 KB |
Output is correct |
5 |
Correct |
84 ms |
16668 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
100 ms |
16708 KB |
Output is correct |
9 |
Correct |
82 ms |
16600 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
0 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
324 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
328 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
580 KB |
Output is correct |
2 |
Correct |
2 ms |
460 KB |
Output is correct |
3 |
Correct |
2 ms |
460 KB |
Output is correct |
4 |
Correct |
2 ms |
460 KB |
Output is correct |
5 |
Correct |
2 ms |
460 KB |
Output is correct |
6 |
Correct |
2 ms |
448 KB |
Output is correct |
7 |
Correct |
2 ms |
588 KB |
Output is correct |
8 |
Correct |
2 ms |
460 KB |
Output is correct |
9 |
Correct |
2 ms |
460 KB |
Output is correct |
10 |
Correct |
2 ms |
588 KB |
Output is correct |
11 |
Correct |
1 ms |
460 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
3 ms |
836 KB |
Output is correct |
5 |
Correct |
84 ms |
16668 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
100 ms |
16708 KB |
Output is correct |
9 |
Correct |
82 ms |
16600 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
0 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
324 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
1 ms |
328 KB |
Output is correct |
20 |
Correct |
2 ms |
580 KB |
Output is correct |
21 |
Correct |
2 ms |
460 KB |
Output is correct |
22 |
Correct |
2 ms |
460 KB |
Output is correct |
23 |
Correct |
2 ms |
460 KB |
Output is correct |
24 |
Correct |
2 ms |
460 KB |
Output is correct |
25 |
Correct |
2 ms |
448 KB |
Output is correct |
26 |
Correct |
2 ms |
588 KB |
Output is correct |
27 |
Correct |
2 ms |
460 KB |
Output is correct |
28 |
Correct |
2 ms |
460 KB |
Output is correct |
29 |
Correct |
2 ms |
588 KB |
Output is correct |
30 |
Correct |
1 ms |
460 KB |
Output is correct |
31 |
Correct |
98 ms |
16648 KB |
Output is correct |
32 |
Correct |
98 ms |
16648 KB |
Output is correct |
33 |
Correct |
105 ms |
16708 KB |
Output is correct |
34 |
Correct |
100 ms |
16596 KB |
Output is correct |
35 |
Correct |
95 ms |
16708 KB |
Output is correct |
36 |
Correct |
83 ms |
16708 KB |
Output is correct |
37 |
Correct |
86 ms |
16708 KB |
Output is correct |
38 |
Correct |
80 ms |
16708 KB |
Output is correct |
39 |
Correct |
85 ms |
16708 KB |
Output is correct |
40 |
Correct |
99 ms |
16672 KB |
Output is correct |
41 |
Correct |
108 ms |
16712 KB |
Output is correct |
42 |
Correct |
109 ms |
16664 KB |
Output is correct |
43 |
Correct |
94 ms |
16652 KB |
Output is correct |
44 |
Correct |
85 ms |
16696 KB |
Output is correct |
45 |
Correct |
112 ms |
16660 KB |
Output is correct |
46 |
Correct |
104 ms |
16708 KB |
Output is correct |
47 |
Correct |
84 ms |
16836 KB |
Output is correct |
48 |
Correct |
100 ms |
16612 KB |
Output is correct |
49 |
Correct |
77 ms |
16712 KB |
Output is correct |
50 |
Correct |
91 ms |
16620 KB |
Output is correct |
51 |
Correct |
106 ms |
16648 KB |
Output is correct |
52 |
Correct |
90 ms |
16716 KB |
Output is correct |
53 |
Correct |
97 ms |
16716 KB |
Output is correct |
54 |
Correct |
96 ms |
16708 KB |
Output is correct |
55 |
Correct |
89 ms |
16640 KB |
Output is correct |
56 |
Correct |
86 ms |
16688 KB |
Output is correct |
57 |
Correct |
88 ms |
16700 KB |
Output is correct |
58 |
Correct |
85 ms |
16696 KB |
Output is correct |