#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pll = pair<ll, ll>;
#define fi first
#define se second
#define sz(a) (ll)a.size()
#define all(a) (a).begin(), (a).end()
const ll N = 2e5 + 5;
const ll V = 1e5 + 5;
const ll blocksz = 450;
const ll mod = 1e9 + 7;
const ll inf = 1e18;
const ld pi = acosl(-1);
ll a[21], b[21], dp[21][1 << 20];
vector<ll> adj[1001];
void doing_job(){
ll n, m; cin >> n >> m;
for (int i = 1; i <= n; ++i){
cin >> a[i];
}
for (int i = 1; i <= m; ++i){
cin >> b[i];
}
for (int mask = 0; mask < (1 << m); ++mask){
ll sum = 0;
for (int i = 0; i < m; ++i){
if (mask >> i & 1){
sum += b[i + 1];
}
}
if (sum <= 1000){
adj[sum].push_back(mask);
}
}
dp[0][0] = 1;
for (int i = 0; i < n; ++i){
for (int mask = 0; mask < (1 << m); ++mask){
if (!dp[i][mask]) continue;
for (ll m : adj[a[i + 1]]){
if (m & mask) continue;
dp[i + 1][mask | m] |= dp[i][mask];
}
}
}
for (int mask = 1; mask < (1 << m); ++mask){
if (dp[n][mask]){
cout << "YES"; return;
}
}
cout << "NO";
}
signed main(){
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
ll t = 1; // cin >> t;
while (t--){
doing_job();
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
2 ms |
1076 KB |
Output is correct |
5 |
Correct |
65 ms |
12560 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
62 ms |
18960 KB |
Output is correct |
9 |
Correct |
68 ms |
11856 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
604 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
604 KB |
Output is correct |
5 |
Correct |
1 ms |
600 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
604 KB |
Output is correct |
8 |
Correct |
1 ms |
604 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
600 KB |
Output is correct |
11 |
Correct |
1 ms |
604 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
2 ms |
1076 KB |
Output is correct |
5 |
Correct |
65 ms |
12560 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
62 ms |
18960 KB |
Output is correct |
9 |
Correct |
68 ms |
11856 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
344 KB |
Output is correct |
21 |
Correct |
1 ms |
604 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
604 KB |
Output is correct |
24 |
Correct |
1 ms |
600 KB |
Output is correct |
25 |
Correct |
1 ms |
344 KB |
Output is correct |
26 |
Correct |
1 ms |
604 KB |
Output is correct |
27 |
Correct |
1 ms |
604 KB |
Output is correct |
28 |
Correct |
1 ms |
344 KB |
Output is correct |
29 |
Correct |
1 ms |
600 KB |
Output is correct |
30 |
Correct |
1 ms |
604 KB |
Output is correct |
31 |
Correct |
73 ms |
12884 KB |
Output is correct |
32 |
Correct |
127 ms |
26752 KB |
Output is correct |
33 |
Correct |
59 ms |
3452 KB |
Output is correct |
34 |
Correct |
67 ms |
724 KB |
Output is correct |
35 |
Correct |
54 ms |
596 KB |
Output is correct |
36 |
Correct |
60 ms |
848 KB |
Output is correct |
37 |
Correct |
48 ms |
728 KB |
Output is correct |
38 |
Correct |
55 ms |
604 KB |
Output is correct |
39 |
Correct |
79 ms |
38736 KB |
Output is correct |
40 |
Correct |
61 ms |
3916 KB |
Output is correct |
41 |
Correct |
57 ms |
1840 KB |
Output is correct |
42 |
Correct |
71 ms |
24932 KB |
Output is correct |
43 |
Correct |
57 ms |
4692 KB |
Output is correct |
44 |
Correct |
60 ms |
592 KB |
Output is correct |
45 |
Correct |
71 ms |
24912 KB |
Output is correct |
46 |
Correct |
57 ms |
10068 KB |
Output is correct |
47 |
Correct |
59 ms |
748 KB |
Output is correct |
48 |
Correct |
64 ms |
17232 KB |
Output is correct |
49 |
Correct |
62 ms |
11864 KB |
Output is correct |
50 |
Correct |
164 ms |
112680 KB |
Output is correct |
51 |
Correct |
63 ms |
11860 KB |
Output is correct |
52 |
Correct |
72 ms |
17848 KB |
Output is correct |
53 |
Correct |
369 ms |
60376 KB |
Output is correct |
54 |
Correct |
165 ms |
107008 KB |
Output is correct |
55 |
Correct |
160 ms |
112508 KB |
Output is correct |
56 |
Correct |
188 ms |
112128 KB |
Output is correct |
57 |
Correct |
175 ms |
104696 KB |
Output is correct |
58 |
Correct |
185 ms |
104848 KB |
Output is correct |