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;
string str;
int n;
void init(int N, int Q, string S) {
n = N;
str = S;
}
int query(string A) {
int ones = 0, zeros = 0;
for (int i = 0; i < n; i++) {
if (A[n-1-i] == '1') {
ones += (1 << i);
}
if (A[n-1-i] == '0') {
zeros += (1 << i);
}
}
int res = 0;
for (int i = 0; i < (1 << n); i++) {
if (i & zeros) continue;
if ((~i) & ones) continue;
res += str[i] - '0';
}
return res;
}
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;
}
}
# | 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... |