#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define endl "\n"
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cout << fixed << setprecision(0);
int l,q;
cin >> l >> q;
int n = (1 << l);
string s;
cin >> s;
map<string, int> cache;
while (q--) {
string a;
cin >> a;
if (cache.find(a) != cache.end()) {
cout << cache[a] << endl;
continue;
}
int ans = 0;
for (int i = 0; i < n; i++) {
for (int bit = 0; bit < l; bit++) {
if ((a[l-bit-1] != '?') && ((a[l-bit-1] == '1') != (bool)(i & (1 << bit)))) {
// cout << "failed: " << bit << " " << (1 << bit) << " as" << i << endl;
// cout << (i & (1 << bit)) << endl;
goto nah;
}
}
// cout << i << " ";
ans += s[i]-'0';
nah:
continue;
}
cache[a] = ans;
cout << ans << endl;
}
}
# | 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... |