#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
#define all(x) x.begin(), x.end()
template <typename T1, typename T2> inline void chkmin(T1 &x, const T2 & y) {if (x > y) x = y;}
template <typename T1, typename T2> inline void chkmax(T1 &x, const T2 & y) {if (x < y) x = y;}
int n, q;
string s;
void read() {
cin >> n >> q;
cin >> s;
}
pair<int, int> get_mask() {
string s;
cin >> s;
int mask = 0;
int must = 0;
for (int i = 0; i < n; i++) {
mask *= 2;
if (s[i] != '0') mask++;
must *= 2;
if (s[i] == '1') must++;
}
return {mask, must};
}
void build() {
}
bool check_submask(int mask, int submask) {
return (mask & submask) == submask;
}
void solve() {
auto x = get_mask();
int mask = x.first, must = x.second;
int ans = 0;
//cout << "mask = " << mask << endl;
for (int i = 0; i < (1 << n); i++) {
ans += (check_submask(mask, i) && check_submask(i, must)) * (s[i] - '0');
}
cout << ans << "\n";
}
void run() {
build();
while (q--) {
solve();
}
}
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
read();
run();
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
376 KB |
Output is correct |
2 |
Correct |
6 ms |
376 KB |
Output is correct |
3 |
Correct |
7 ms |
248 KB |
Output is correct |
4 |
Correct |
6 ms |
380 KB |
Output is correct |
5 |
Correct |
6 ms |
376 KB |
Output is correct |
6 |
Correct |
6 ms |
376 KB |
Output is correct |
7 |
Correct |
7 ms |
376 KB |
Output is correct |
8 |
Correct |
7 ms |
376 KB |
Output is correct |
9 |
Correct |
7 ms |
376 KB |
Output is correct |
10 |
Correct |
7 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
376 KB |
Output is correct |
2 |
Correct |
6 ms |
376 KB |
Output is correct |
3 |
Correct |
7 ms |
248 KB |
Output is correct |
4 |
Correct |
6 ms |
380 KB |
Output is correct |
5 |
Correct |
6 ms |
376 KB |
Output is correct |
6 |
Correct |
6 ms |
376 KB |
Output is correct |
7 |
Correct |
7 ms |
376 KB |
Output is correct |
8 |
Correct |
7 ms |
376 KB |
Output is correct |
9 |
Correct |
7 ms |
376 KB |
Output is correct |
10 |
Correct |
7 ms |
376 KB |
Output is correct |
11 |
Correct |
1720 ms |
15224 KB |
Output is correct |
12 |
Correct |
1710 ms |
14984 KB |
Output is correct |
13 |
Correct |
1681 ms |
14268 KB |
Output is correct |
14 |
Correct |
1710 ms |
14456 KB |
Output is correct |
15 |
Correct |
1749 ms |
15252 KB |
Output is correct |
16 |
Correct |
1752 ms |
14456 KB |
Output is correct |
17 |
Correct |
1735 ms |
14496 KB |
Output is correct |
18 |
Correct |
1714 ms |
16376 KB |
Output is correct |
19 |
Correct |
1660 ms |
13304 KB |
Output is correct |
20 |
Correct |
1744 ms |
14840 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
376 KB |
Output is correct |
2 |
Correct |
6 ms |
376 KB |
Output is correct |
3 |
Correct |
7 ms |
248 KB |
Output is correct |
4 |
Correct |
6 ms |
380 KB |
Output is correct |
5 |
Correct |
6 ms |
376 KB |
Output is correct |
6 |
Correct |
6 ms |
376 KB |
Output is correct |
7 |
Correct |
7 ms |
376 KB |
Output is correct |
8 |
Correct |
7 ms |
376 KB |
Output is correct |
9 |
Correct |
7 ms |
376 KB |
Output is correct |
10 |
Correct |
7 ms |
376 KB |
Output is correct |
11 |
Correct |
1720 ms |
15224 KB |
Output is correct |
12 |
Correct |
1710 ms |
14984 KB |
Output is correct |
13 |
Correct |
1681 ms |
14268 KB |
Output is correct |
14 |
Correct |
1710 ms |
14456 KB |
Output is correct |
15 |
Correct |
1749 ms |
15252 KB |
Output is correct |
16 |
Correct |
1752 ms |
14456 KB |
Output is correct |
17 |
Correct |
1735 ms |
14496 KB |
Output is correct |
18 |
Correct |
1714 ms |
16376 KB |
Output is correct |
19 |
Correct |
1660 ms |
13304 KB |
Output is correct |
20 |
Correct |
1744 ms |
14840 KB |
Output is correct |
21 |
Execution timed out |
2062 ms |
3804 KB |
Time limit exceeded |
22 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
376 KB |
Output is correct |
2 |
Correct |
6 ms |
376 KB |
Output is correct |
3 |
Correct |
7 ms |
248 KB |
Output is correct |
4 |
Correct |
6 ms |
380 KB |
Output is correct |
5 |
Correct |
6 ms |
376 KB |
Output is correct |
6 |
Correct |
6 ms |
376 KB |
Output is correct |
7 |
Correct |
7 ms |
376 KB |
Output is correct |
8 |
Correct |
7 ms |
376 KB |
Output is correct |
9 |
Correct |
7 ms |
376 KB |
Output is correct |
10 |
Correct |
7 ms |
376 KB |
Output is correct |
11 |
Execution timed out |
2053 ms |
3728 KB |
Time limit exceeded |
12 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
376 KB |
Output is correct |
2 |
Correct |
6 ms |
376 KB |
Output is correct |
3 |
Correct |
7 ms |
248 KB |
Output is correct |
4 |
Correct |
6 ms |
380 KB |
Output is correct |
5 |
Correct |
6 ms |
376 KB |
Output is correct |
6 |
Correct |
6 ms |
376 KB |
Output is correct |
7 |
Correct |
7 ms |
376 KB |
Output is correct |
8 |
Correct |
7 ms |
376 KB |
Output is correct |
9 |
Correct |
7 ms |
376 KB |
Output is correct |
10 |
Correct |
7 ms |
376 KB |
Output is correct |
11 |
Correct |
1720 ms |
15224 KB |
Output is correct |
12 |
Correct |
1710 ms |
14984 KB |
Output is correct |
13 |
Correct |
1681 ms |
14268 KB |
Output is correct |
14 |
Correct |
1710 ms |
14456 KB |
Output is correct |
15 |
Correct |
1749 ms |
15252 KB |
Output is correct |
16 |
Correct |
1752 ms |
14456 KB |
Output is correct |
17 |
Correct |
1735 ms |
14496 KB |
Output is correct |
18 |
Correct |
1714 ms |
16376 KB |
Output is correct |
19 |
Correct |
1660 ms |
13304 KB |
Output is correct |
20 |
Correct |
1744 ms |
14840 KB |
Output is correct |
21 |
Execution timed out |
2062 ms |
3804 KB |
Time limit exceeded |
22 |
Halted |
0 ms |
0 KB |
- |