#include <bits/stdc++.h>
using namespace std;
const int L = 20;
int n, q;
string str;
int a, b;
int val[1<<L];
int ans;
signed main() {
ios_base::sync_with_stdio(0), cin.tie(0);
cin >> n >> q;
cin >> str;
for (int i = 0; i < (1<<n); i++)
val[i] = str[i] - '0';
for (int i = 0; i < q; i++) {
cin >> str;
a = 0, b = 0;
for (int j = 0; j < n; j++) {
if (str[j] == '?')
a = a*2, b = b*2+1;
else if (str[j] == '0')
a = a*2, b = b*2;
else
a = a*2+1, b = b*2+1;
}
ans = 0;
for (int j = a; j <= b; j++) {
if ((a&j) == a && (b|j) == b) {
ans += val[j];
}
}
cout << ans << "\n";
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
2 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
2 ms |
364 KB |
Output is correct |
8 |
Correct |
3 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
2 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
2 ms |
364 KB |
Output is correct |
8 |
Correct |
3 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
649 ms |
6124 KB |
Output is correct |
12 |
Correct |
765 ms |
4332 KB |
Output is correct |
13 |
Correct |
561 ms |
3436 KB |
Output is correct |
14 |
Correct |
667 ms |
3724 KB |
Output is correct |
15 |
Correct |
977 ms |
4804 KB |
Output is correct |
16 |
Correct |
742 ms |
3996 KB |
Output is correct |
17 |
Correct |
715 ms |
3764 KB |
Output is correct |
18 |
Correct |
1022 ms |
5776 KB |
Output is correct |
19 |
Correct |
219 ms |
2540 KB |
Output is correct |
20 |
Correct |
678 ms |
4460 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
2 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
2 ms |
364 KB |
Output is correct |
8 |
Correct |
3 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
649 ms |
6124 KB |
Output is correct |
12 |
Correct |
765 ms |
4332 KB |
Output is correct |
13 |
Correct |
561 ms |
3436 KB |
Output is correct |
14 |
Correct |
667 ms |
3724 KB |
Output is correct |
15 |
Correct |
977 ms |
4804 KB |
Output is correct |
16 |
Correct |
742 ms |
3996 KB |
Output is correct |
17 |
Correct |
715 ms |
3764 KB |
Output is correct |
18 |
Correct |
1022 ms |
5776 KB |
Output is correct |
19 |
Correct |
219 ms |
2540 KB |
Output is correct |
20 |
Correct |
678 ms |
4460 KB |
Output is correct |
21 |
Execution timed out |
2075 ms |
3464 KB |
Time limit exceeded |
22 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
2 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
2 ms |
364 KB |
Output is correct |
8 |
Correct |
3 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Execution timed out |
2072 ms |
6432 KB |
Time limit exceeded |
12 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
2 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
2 ms |
364 KB |
Output is correct |
8 |
Correct |
3 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
649 ms |
6124 KB |
Output is correct |
12 |
Correct |
765 ms |
4332 KB |
Output is correct |
13 |
Correct |
561 ms |
3436 KB |
Output is correct |
14 |
Correct |
667 ms |
3724 KB |
Output is correct |
15 |
Correct |
977 ms |
4804 KB |
Output is correct |
16 |
Correct |
742 ms |
3996 KB |
Output is correct |
17 |
Correct |
715 ms |
3764 KB |
Output is correct |
18 |
Correct |
1022 ms |
5776 KB |
Output is correct |
19 |
Correct |
219 ms |
2540 KB |
Output is correct |
20 |
Correct |
678 ms |
4460 KB |
Output is correct |
21 |
Execution timed out |
2075 ms |
3464 KB |
Time limit exceeded |
22 |
Halted |
0 ms |
0 KB |
- |