#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair <ll,ll> pll;
typedef pair <int,int> pii;
typedef pair <int,pii> piii;
#define forr(_a,_b,_c) for(int _a = (_b); _a <= (_c); ++_a)
#define ford(_a,_b,_c) for(int _a = (_b) + 1; _a --> (_c);)
#define forf(_a,_b,_c) for(int _a = (_b); _a < (_c); ++_a)
#define st first
#define nd second
#define pb push_back
#define mp make_pair
#define all(x) begin(x),end(x)
#define mask(i) (1LL << (i))
#define bit(x, i) (((x) >> (i)) & 1)
#define bp __builtin_popcountll
#define file "test"
template<class X, class Y>
bool minz(X &x, const Y &y) {
if (x > y) {
x = y;
return true;
} return false;
}
template<class X, class Y>
bool maxz(X &x, const Y &y) {
if (x < y) {
x = y;
return true;
} return false;
}
const int N = 5e5 + 5;
const ll oo = (ll) 1e16;
const ll mod = 1e9 + 7; // 998244353;
int l, q, f[mask(20)], g[mask(20)], mul[2] = {1, -1};
string s;
int main(){
ios_base::sync_with_stdio(0); cin.tie(0);
#ifdef hqm
freopen(file".inp", "r", stdin); freopen(file".out", "w", stdout);
#endif
cin >> l >> q >> s;
forf (i, 0, s.size()){
f[i] = s[i] - '0';
g[i] = s[i] - '0';
}
forf (i, 0, l){
forf (j, 0, mask(l)){
if (bit(j, i)){
f[j] += f[j ^ mask(i)];
}
}
}
ford (i, l - 1, 0){
ford (j, mask(l) - 1, 0){
if (bit(j, i))
g[j ^ mask(i)] += g[j];
}
}
while (q--){
int fo = 0, fz = 0, fq = 0, res = 0;
cin >> s;
reverse(all(s));
forf (i, 0, l){
if (s[i] == '?') fq ^= mask(i);
else if (s[i] == '0') fz ^= mask(i);
else fo ^= mask(i);
}
if (bp(fz) <= 6){
//cout << fo << "\n";
for (int i = fz; ; i = (i - 1) & fz){
res += g[i | fo] * mul[bp(i) & 1];
//cout << g[i] << " " << mul[bp(i) & 1] << "\n";
if (i == 0) break;
}
} else
if (bp(fo) <= 6){
for (int i = fo; ; i = (i - 1) & fo){
res += f[i | fq] * mul[(bp(fo) ^ bp(i)) & 1];
if (i == 0) break;
}
} else {
for (int i = fq; ; i = (i - 1) & fq){
res += s[i | fo] - '0';
if (i == 0) break;
}
}
cout << res << "\n";
}
return 0;
}
/*
*/
Compilation message
snake_escaping.cpp: In function 'int main()':
snake_escaping.cpp:11:46: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
11 | #define forf(_a,_b,_c) for(int _a = (_b); _a < (_c); ++_a)
| ^
snake_escaping.cpp:52:5: note: in expansion of macro 'forf'
52 | forf (i, 0, s.size()){
| ^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
139 ms |
15160 KB |
Output is correct |
12 |
Correct |
211 ms |
14892 KB |
Output is correct |
13 |
Correct |
244 ms |
14068 KB |
Output is correct |
14 |
Correct |
193 ms |
14028 KB |
Output is correct |
15 |
Correct |
165 ms |
15184 KB |
Output is correct |
16 |
Correct |
181 ms |
14376 KB |
Output is correct |
17 |
Correct |
228 ms |
14164 KB |
Output is correct |
18 |
Correct |
100 ms |
16048 KB |
Output is correct |
19 |
Correct |
219 ms |
13140 KB |
Output is correct |
20 |
Correct |
145 ms |
14672 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
139 ms |
15160 KB |
Output is correct |
12 |
Correct |
211 ms |
14892 KB |
Output is correct |
13 |
Correct |
244 ms |
14068 KB |
Output is correct |
14 |
Correct |
193 ms |
14028 KB |
Output is correct |
15 |
Correct |
165 ms |
15184 KB |
Output is correct |
16 |
Correct |
181 ms |
14376 KB |
Output is correct |
17 |
Correct |
228 ms |
14164 KB |
Output is correct |
18 |
Correct |
100 ms |
16048 KB |
Output is correct |
19 |
Correct |
219 ms |
13140 KB |
Output is correct |
20 |
Correct |
145 ms |
14672 KB |
Output is correct |
21 |
Correct |
153 ms |
18072 KB |
Output is correct |
22 |
Correct |
235 ms |
18296 KB |
Output is correct |
23 |
Correct |
353 ms |
17292 KB |
Output is correct |
24 |
Correct |
264 ms |
17252 KB |
Output is correct |
25 |
Correct |
206 ms |
19024 KB |
Output is correct |
26 |
Correct |
240 ms |
17664 KB |
Output is correct |
27 |
Correct |
253 ms |
17488 KB |
Output is correct |
28 |
Correct |
108 ms |
20052 KB |
Output is correct |
29 |
Correct |
328 ms |
16100 KB |
Output is correct |
30 |
Correct |
176 ms |
18412 KB |
Output is correct |
31 |
Correct |
235 ms |
18268 KB |
Output is correct |
32 |
Correct |
229 ms |
18260 KB |
Output is correct |
33 |
Correct |
190 ms |
16976 KB |
Output is correct |
34 |
Correct |
263 ms |
17136 KB |
Output is correct |
35 |
Correct |
255 ms |
17488 KB |
Output is correct |
36 |
Correct |
106 ms |
16072 KB |
Output is correct |
37 |
Correct |
156 ms |
18256 KB |
Output is correct |
38 |
Correct |
284 ms |
16008 KB |
Output is correct |
39 |
Correct |
227 ms |
17232 KB |
Output is correct |
40 |
Correct |
221 ms |
17160 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
44 ms |
12100 KB |
Output is correct |
12 |
Correct |
46 ms |
11884 KB |
Output is correct |
13 |
Correct |
50 ms |
11848 KB |
Output is correct |
14 |
Correct |
59 ms |
12020 KB |
Output is correct |
15 |
Correct |
53 ms |
12092 KB |
Output is correct |
16 |
Correct |
58 ms |
12040 KB |
Output is correct |
17 |
Correct |
53 ms |
12020 KB |
Output is correct |
18 |
Correct |
40 ms |
12108 KB |
Output is correct |
19 |
Correct |
43 ms |
11848 KB |
Output is correct |
20 |
Correct |
44 ms |
12020 KB |
Output is correct |
21 |
Correct |
51 ms |
12100 KB |
Output is correct |
22 |
Correct |
58 ms |
11840 KB |
Output is correct |
23 |
Correct |
47 ms |
11788 KB |
Output is correct |
24 |
Correct |
55 ms |
12020 KB |
Output is correct |
25 |
Correct |
54 ms |
12016 KB |
Output is correct |
26 |
Correct |
40 ms |
11764 KB |
Output is correct |
27 |
Correct |
44 ms |
12024 KB |
Output is correct |
28 |
Correct |
49 ms |
11760 KB |
Output is correct |
29 |
Correct |
51 ms |
11852 KB |
Output is correct |
30 |
Correct |
50 ms |
12012 KB |
Output is correct |
31 |
Correct |
51 ms |
11848 KB |
Output is correct |
32 |
Correct |
59 ms |
11840 KB |
Output is correct |
33 |
Correct |
53 ms |
12024 KB |
Output is correct |
34 |
Correct |
40 ms |
11836 KB |
Output is correct |
35 |
Correct |
50 ms |
11848 KB |
Output is correct |
36 |
Correct |
56 ms |
12112 KB |
Output is correct |
37 |
Correct |
50 ms |
12020 KB |
Output is correct |
38 |
Correct |
51 ms |
12016 KB |
Output is correct |
39 |
Correct |
51 ms |
12020 KB |
Output is correct |
40 |
Correct |
50 ms |
12020 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
139 ms |
15160 KB |
Output is correct |
12 |
Correct |
211 ms |
14892 KB |
Output is correct |
13 |
Correct |
244 ms |
14068 KB |
Output is correct |
14 |
Correct |
193 ms |
14028 KB |
Output is correct |
15 |
Correct |
165 ms |
15184 KB |
Output is correct |
16 |
Correct |
181 ms |
14376 KB |
Output is correct |
17 |
Correct |
228 ms |
14164 KB |
Output is correct |
18 |
Correct |
100 ms |
16048 KB |
Output is correct |
19 |
Correct |
219 ms |
13140 KB |
Output is correct |
20 |
Correct |
145 ms |
14672 KB |
Output is correct |
21 |
Correct |
153 ms |
18072 KB |
Output is correct |
22 |
Correct |
235 ms |
18296 KB |
Output is correct |
23 |
Correct |
353 ms |
17292 KB |
Output is correct |
24 |
Correct |
264 ms |
17252 KB |
Output is correct |
25 |
Correct |
206 ms |
19024 KB |
Output is correct |
26 |
Correct |
240 ms |
17664 KB |
Output is correct |
27 |
Correct |
253 ms |
17488 KB |
Output is correct |
28 |
Correct |
108 ms |
20052 KB |
Output is correct |
29 |
Correct |
328 ms |
16100 KB |
Output is correct |
30 |
Correct |
176 ms |
18412 KB |
Output is correct |
31 |
Correct |
235 ms |
18268 KB |
Output is correct |
32 |
Correct |
229 ms |
18260 KB |
Output is correct |
33 |
Correct |
190 ms |
16976 KB |
Output is correct |
34 |
Correct |
263 ms |
17136 KB |
Output is correct |
35 |
Correct |
255 ms |
17488 KB |
Output is correct |
36 |
Correct |
106 ms |
16072 KB |
Output is correct |
37 |
Correct |
156 ms |
18256 KB |
Output is correct |
38 |
Correct |
284 ms |
16008 KB |
Output is correct |
39 |
Correct |
227 ms |
17232 KB |
Output is correct |
40 |
Correct |
221 ms |
17160 KB |
Output is correct |
41 |
Correct |
44 ms |
12100 KB |
Output is correct |
42 |
Correct |
46 ms |
11884 KB |
Output is correct |
43 |
Correct |
50 ms |
11848 KB |
Output is correct |
44 |
Correct |
59 ms |
12020 KB |
Output is correct |
45 |
Correct |
53 ms |
12092 KB |
Output is correct |
46 |
Correct |
58 ms |
12040 KB |
Output is correct |
47 |
Correct |
53 ms |
12020 KB |
Output is correct |
48 |
Correct |
40 ms |
12108 KB |
Output is correct |
49 |
Correct |
43 ms |
11848 KB |
Output is correct |
50 |
Correct |
44 ms |
12020 KB |
Output is correct |
51 |
Correct |
51 ms |
12100 KB |
Output is correct |
52 |
Correct |
58 ms |
11840 KB |
Output is correct |
53 |
Correct |
47 ms |
11788 KB |
Output is correct |
54 |
Correct |
55 ms |
12020 KB |
Output is correct |
55 |
Correct |
54 ms |
12016 KB |
Output is correct |
56 |
Correct |
40 ms |
11764 KB |
Output is correct |
57 |
Correct |
44 ms |
12024 KB |
Output is correct |
58 |
Correct |
49 ms |
11760 KB |
Output is correct |
59 |
Correct |
51 ms |
11852 KB |
Output is correct |
60 |
Correct |
50 ms |
12012 KB |
Output is correct |
61 |
Correct |
51 ms |
11848 KB |
Output is correct |
62 |
Correct |
59 ms |
11840 KB |
Output is correct |
63 |
Correct |
53 ms |
12024 KB |
Output is correct |
64 |
Correct |
40 ms |
11836 KB |
Output is correct |
65 |
Correct |
50 ms |
11848 KB |
Output is correct |
66 |
Correct |
56 ms |
12112 KB |
Output is correct |
67 |
Correct |
50 ms |
12020 KB |
Output is correct |
68 |
Correct |
51 ms |
12016 KB |
Output is correct |
69 |
Correct |
51 ms |
12020 KB |
Output is correct |
70 |
Correct |
50 ms |
12020 KB |
Output is correct |
71 |
Correct |
245 ms |
36264 KB |
Output is correct |
72 |
Correct |
266 ms |
36432 KB |
Output is correct |
73 |
Correct |
368 ms |
35064 KB |
Output is correct |
74 |
Correct |
532 ms |
35352 KB |
Output is correct |
75 |
Correct |
315 ms |
37452 KB |
Output is correct |
76 |
Correct |
536 ms |
35568 KB |
Output is correct |
77 |
Correct |
432 ms |
35572 KB |
Output is correct |
78 |
Correct |
170 ms |
39276 KB |
Output is correct |
79 |
Correct |
235 ms |
33264 KB |
Output is correct |
80 |
Correct |
253 ms |
36336 KB |
Output is correct |
81 |
Correct |
386 ms |
36412 KB |
Output is correct |
82 |
Correct |
529 ms |
35384 KB |
Output is correct |
83 |
Correct |
299 ms |
34572 KB |
Output is correct |
84 |
Correct |
470 ms |
35312 KB |
Output is correct |
85 |
Correct |
442 ms |
35372 KB |
Output is correct |
86 |
Correct |
152 ms |
33400 KB |
Output is correct |
87 |
Correct |
248 ms |
36416 KB |
Output is correct |
88 |
Correct |
278 ms |
33244 KB |
Output is correct |
89 |
Correct |
363 ms |
34892 KB |
Output is correct |
90 |
Correct |
379 ms |
35308 KB |
Output is correct |
91 |
Correct |
285 ms |
34352 KB |
Output is correct |
92 |
Correct |
528 ms |
35568 KB |
Output is correct |
93 |
Correct |
431 ms |
35568 KB |
Output is correct |
94 |
Correct |
163 ms |
33280 KB |
Output is correct |
95 |
Correct |
376 ms |
35252 KB |
Output is correct |
96 |
Correct |
392 ms |
35316 KB |
Output is correct |
97 |
Correct |
367 ms |
35260 KB |
Output is correct |
98 |
Correct |
411 ms |
35396 KB |
Output is correct |
99 |
Correct |
385 ms |
35596 KB |
Output is correct |
100 |
Correct |
383 ms |
35460 KB |
Output is correct |