# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
943410 | guechotjrhh | Snake Escaping (JOI18_snake_escaping) | C++17 | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<iostream>
#include<string>
using namespace std;
#include<map>
#include<string>
using namespace std;
#define all(x) x.begin(),x.end()
string str;
int n;
map<string, int> mp;
string itos(int a, int l) {
string res = "";
for (int i = 0; i < l; i++) {
res += '0' + (a & 1);
a >>= 1;
}
reverse(all(res));
return res;
}
void init(int N, int Q, string S) {
n = N;
str = S;
for (int i = 0; i < (1 << n); i++) {
for (int j = 0; j < (1 << n); j++) {
string s = itos(i, n);
for (int w = 0; w < n; w++) if (j & (1 << w)) s[w] = '?';
mp[s] += S[i]-'0';
}
}
}
int query(string A) {
return mp[A];
}
int main() {
ios::sync_with_stdio(0); cin.tie(0);
int N, Q; cin >> N >> Q;
string S; cin >> S;
init(N, Q, move(S));
for (int i = 0; i < Q; i++) {
string A;
cin >> A;
cout << query(move(A)) << endl;
}
}