#include <bits/stdc++.h>
#define ll long long
#define pii pair <ll, ll>
#define st first
#define nd second
#define rep(i, n, m) for (ll i = (n); i <= (m); i ++)
#define rrep(i, n, m) for (ll i = (n); i >= (m); i --)
using namespace std;
const long long INF = 1e18;
const long long N = 1e6 + 5;
const long long mask_Max = 2e6;
int n, q, L;
ll a[N], f[mask_Max];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
//freopen("test.inp", "r", stdin);
//freopen("test.out", "w", stdout);
cin >> L >> q;
n = 1ll << L;
rep(i, 0, n - 1) {
char ch;
cin >> ch;
a[i] = ch - '0';
}
rep(i, 0, n - 1) {
rep(j, 0, n - 1) {
ll cur = 0;
rep(k, 0, L - 1) {
ll val = 2;
if (j >> k & 1) {
if (i >> k & 1) val = 1; else val = 0;
}
cur = cur * 3 + val;
}
f[cur] += a[i];
}
}
string t;
while (q --) {
cin >> t;
reverse(t.begin(), t.end());
ll val = 0;
rep(i, 0, L - 1) {
if (t[i] == '1') val = val * 3 + 1;
if (t[i] == '0') val = val * 3;
if (t[i] == '?') val = val * 3 + 2;
}
cout << f[val] << '\n';
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
724 KB |
Output is correct |
2 |
Correct |
12 ms |
824 KB |
Output is correct |
3 |
Correct |
12 ms |
724 KB |
Output is correct |
4 |
Correct |
13 ms |
820 KB |
Output is correct |
5 |
Correct |
12 ms |
724 KB |
Output is correct |
6 |
Correct |
13 ms |
820 KB |
Output is correct |
7 |
Correct |
12 ms |
724 KB |
Output is correct |
8 |
Correct |
14 ms |
724 KB |
Output is correct |
9 |
Correct |
12 ms |
728 KB |
Output is correct |
10 |
Correct |
12 ms |
724 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
724 KB |
Output is correct |
2 |
Correct |
12 ms |
824 KB |
Output is correct |
3 |
Correct |
12 ms |
724 KB |
Output is correct |
4 |
Correct |
13 ms |
820 KB |
Output is correct |
5 |
Correct |
12 ms |
724 KB |
Output is correct |
6 |
Correct |
13 ms |
820 KB |
Output is correct |
7 |
Correct |
12 ms |
724 KB |
Output is correct |
8 |
Correct |
14 ms |
724 KB |
Output is correct |
9 |
Correct |
12 ms |
728 KB |
Output is correct |
10 |
Correct |
12 ms |
724 KB |
Output is correct |
11 |
Correct |
192 ms |
5112 KB |
Output is correct |
12 |
Correct |
218 ms |
4716 KB |
Output is correct |
13 |
Correct |
202 ms |
3992 KB |
Output is correct |
14 |
Correct |
206 ms |
4124 KB |
Output is correct |
15 |
Correct |
195 ms |
5044 KB |
Output is correct |
16 |
Correct |
221 ms |
4312 KB |
Output is correct |
17 |
Correct |
217 ms |
4280 KB |
Output is correct |
18 |
Correct |
182 ms |
6252 KB |
Output is correct |
19 |
Correct |
184 ms |
3240 KB |
Output is correct |
20 |
Correct |
203 ms |
4752 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
724 KB |
Output is correct |
2 |
Correct |
12 ms |
824 KB |
Output is correct |
3 |
Correct |
12 ms |
724 KB |
Output is correct |
4 |
Correct |
13 ms |
820 KB |
Output is correct |
5 |
Correct |
12 ms |
724 KB |
Output is correct |
6 |
Correct |
13 ms |
820 KB |
Output is correct |
7 |
Correct |
12 ms |
724 KB |
Output is correct |
8 |
Correct |
14 ms |
724 KB |
Output is correct |
9 |
Correct |
12 ms |
728 KB |
Output is correct |
10 |
Correct |
12 ms |
724 KB |
Output is correct |
11 |
Correct |
192 ms |
5112 KB |
Output is correct |
12 |
Correct |
218 ms |
4716 KB |
Output is correct |
13 |
Correct |
202 ms |
3992 KB |
Output is correct |
14 |
Correct |
206 ms |
4124 KB |
Output is correct |
15 |
Correct |
195 ms |
5044 KB |
Output is correct |
16 |
Correct |
221 ms |
4312 KB |
Output is correct |
17 |
Correct |
217 ms |
4280 KB |
Output is correct |
18 |
Correct |
182 ms |
6252 KB |
Output is correct |
19 |
Correct |
184 ms |
3240 KB |
Output is correct |
20 |
Correct |
203 ms |
4752 KB |
Output is correct |
21 |
Correct |
1356 ms |
17208 KB |
Output is correct |
22 |
Correct |
1363 ms |
17328 KB |
Output is correct |
23 |
Correct |
1467 ms |
16424 KB |
Output is correct |
24 |
Correct |
1529 ms |
16232 KB |
Output is correct |
25 |
Correct |
1523 ms |
18092 KB |
Output is correct |
26 |
Correct |
1514 ms |
16812 KB |
Output is correct |
27 |
Correct |
1472 ms |
16584 KB |
Output is correct |
28 |
Correct |
1453 ms |
19148 KB |
Output is correct |
29 |
Correct |
1380 ms |
15088 KB |
Output is correct |
30 |
Correct |
1399 ms |
17328 KB |
Output is correct |
31 |
Correct |
1438 ms |
17096 KB |
Output is correct |
32 |
Correct |
1461 ms |
17104 KB |
Output is correct |
33 |
Correct |
1463 ms |
16040 KB |
Output is correct |
34 |
Correct |
1501 ms |
16176 KB |
Output is correct |
35 |
Correct |
1439 ms |
16572 KB |
Output is correct |
36 |
Correct |
1422 ms |
15172 KB |
Output is correct |
37 |
Correct |
1509 ms |
17100 KB |
Output is correct |
38 |
Correct |
1370 ms |
15224 KB |
Output is correct |
39 |
Correct |
1410 ms |
16300 KB |
Output is correct |
40 |
Correct |
1461 ms |
16172 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
724 KB |
Output is correct |
2 |
Correct |
12 ms |
824 KB |
Output is correct |
3 |
Correct |
12 ms |
724 KB |
Output is correct |
4 |
Correct |
13 ms |
820 KB |
Output is correct |
5 |
Correct |
12 ms |
724 KB |
Output is correct |
6 |
Correct |
13 ms |
820 KB |
Output is correct |
7 |
Correct |
12 ms |
724 KB |
Output is correct |
8 |
Correct |
14 ms |
724 KB |
Output is correct |
9 |
Correct |
12 ms |
728 KB |
Output is correct |
10 |
Correct |
12 ms |
724 KB |
Output is correct |
11 |
Incorrect |
15 ms |
8396 KB |
Output isn't correct |
12 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
724 KB |
Output is correct |
2 |
Correct |
12 ms |
824 KB |
Output is correct |
3 |
Correct |
12 ms |
724 KB |
Output is correct |
4 |
Correct |
13 ms |
820 KB |
Output is correct |
5 |
Correct |
12 ms |
724 KB |
Output is correct |
6 |
Correct |
13 ms |
820 KB |
Output is correct |
7 |
Correct |
12 ms |
724 KB |
Output is correct |
8 |
Correct |
14 ms |
724 KB |
Output is correct |
9 |
Correct |
12 ms |
728 KB |
Output is correct |
10 |
Correct |
12 ms |
724 KB |
Output is correct |
11 |
Correct |
192 ms |
5112 KB |
Output is correct |
12 |
Correct |
218 ms |
4716 KB |
Output is correct |
13 |
Correct |
202 ms |
3992 KB |
Output is correct |
14 |
Correct |
206 ms |
4124 KB |
Output is correct |
15 |
Correct |
195 ms |
5044 KB |
Output is correct |
16 |
Correct |
221 ms |
4312 KB |
Output is correct |
17 |
Correct |
217 ms |
4280 KB |
Output is correct |
18 |
Correct |
182 ms |
6252 KB |
Output is correct |
19 |
Correct |
184 ms |
3240 KB |
Output is correct |
20 |
Correct |
203 ms |
4752 KB |
Output is correct |
21 |
Correct |
1356 ms |
17208 KB |
Output is correct |
22 |
Correct |
1363 ms |
17328 KB |
Output is correct |
23 |
Correct |
1467 ms |
16424 KB |
Output is correct |
24 |
Correct |
1529 ms |
16232 KB |
Output is correct |
25 |
Correct |
1523 ms |
18092 KB |
Output is correct |
26 |
Correct |
1514 ms |
16812 KB |
Output is correct |
27 |
Correct |
1472 ms |
16584 KB |
Output is correct |
28 |
Correct |
1453 ms |
19148 KB |
Output is correct |
29 |
Correct |
1380 ms |
15088 KB |
Output is correct |
30 |
Correct |
1399 ms |
17328 KB |
Output is correct |
31 |
Correct |
1438 ms |
17096 KB |
Output is correct |
32 |
Correct |
1461 ms |
17104 KB |
Output is correct |
33 |
Correct |
1463 ms |
16040 KB |
Output is correct |
34 |
Correct |
1501 ms |
16176 KB |
Output is correct |
35 |
Correct |
1439 ms |
16572 KB |
Output is correct |
36 |
Correct |
1422 ms |
15172 KB |
Output is correct |
37 |
Correct |
1509 ms |
17100 KB |
Output is correct |
38 |
Correct |
1370 ms |
15224 KB |
Output is correct |
39 |
Correct |
1410 ms |
16300 KB |
Output is correct |
40 |
Correct |
1461 ms |
16172 KB |
Output is correct |
41 |
Incorrect |
15 ms |
8396 KB |
Output isn't correct |
42 |
Halted |
0 ms |
0 KB |
- |