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 <bits/stdc++.h>
using namespace std;
int n, q;
string s;
int solve(const string& t, int qm) {
int sum = 0;
for (int i = 0; i < (1 << qm); i++) {
int c = 0;
int idx = 0;
for (int j = 0; j < n; j++) {
if (t[j] == '1') {
c += 1 << j;
}
if (t[j] == '?') {
if (i & (1 << idx)) {
c += 1 << j;
}
idx++;
}
}
sum += (s[c] - '0');
}
return sum;
}
int main() {
cin >> n >> q;
cin >> s;
while (q--) {
string t;
cin >> t;
reverse(t.begin(), t.end());
cout << solve(t, count(t.begin(), t.end(), '?')) << 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... |