#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int, int>
#define fi first
#define se second
const int N = 1e6 + 5;
int L, Q;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> L >> Q;
string s, t;
cin >> s;
int n = 1 << L;
while (Q--) {
cin >> t;
ll ans = 0;
for (int i = 0; i < n; i++) {
bool ok = 1;
for (int j = 0; j < L; j++) {
char c = t[j];
if (c == '?') continue;
int bit = (i >> (L - 1 - j)) & 1;
if (c == '0' && bit != 0) {ok = 0; break;}
if (c == '1' && bit != 1) {ok = 0; break;}
}
if (ok) ans += (s[i] - '0');
}
cout << ans << '\n';
}
}
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |