/* Author : Mychecksdead */
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define MOD (1000000000+7)
#define MOD1 (998244353)
#define pb push_back
#define all(x) x.begin(), x.end()
#define en cout << '\n'
const int N = 2e6+100, M = 1e5+10, K = 13, MX = 30;
int n, q, dp[N];
string s;
void solve(){
cin >> n >> q >> s;
for(int i = 0; i < (1<<n); ++i) dp[i] = s[i] - '0';
for(int i = 0; i < n; ++i){
for(int mask = 0; mask < (1<<n); ++mask){
if(((1<<i)&mask) == 0) dp[mask] += dp[(1<<i) ^ mask];
}
}
for(int i = 0; i < q; ++i){
string t; cin >> t;
int A = 0, B = 0, C = 0;
for(int j = 0; j < n; ++j){
if(t[n-j-1] == '0') A += (1<<j);
if(t[n-j-1] == '1') B += (1<<j);
if(t[n-j-1] == '?') C += (1<<j);
}
if(__builtin_popcount(C) <= 6){
int ans = 0;
for(int S = C; S > 0; S = (S-1)&C){
ans += s[S | B] - '0';
}
ans += s[B] - '0';
cout << ans << '\n';
}else{
int ans = 0;
for(int S = A; S > 0; S = (S-1)&A){
ans += dp[B | S] * (__builtin_popcount(S) % 2 == 0 ? 1 : -1);
}
ans += dp[B];
cout << ans << '\n';
}
}
}
int main(){
cin.tie(0); ios::sync_with_stdio(0);
int tt = 1, aa;
// freopen("in.txt", "r", stdin);
// freopen("out.txt", "w", stdout);
// cin >> tt;
while(tt--){
solve();
// en;
}
cerr<<"time taken : "<<(float)clock()/CLOCKS_PER_SEC<<" seconds\n";
return 0;
}
Compilation message
snake_escaping.cpp: In function 'int main()':
snake_escaping.cpp:53:15: warning: unused variable 'aa' [-Wunused-variable]
53 | int tt = 1, aa;
| ^~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
187 ms |
11008 KB |
Output is correct |
12 |
Correct |
198 ms |
10068 KB |
Output is correct |
13 |
Correct |
196 ms |
7916 KB |
Output is correct |
14 |
Correct |
185 ms |
8072 KB |
Output is correct |
15 |
Correct |
230 ms |
11264 KB |
Output is correct |
16 |
Correct |
201 ms |
9016 KB |
Output is correct |
17 |
Correct |
216 ms |
8788 KB |
Output is correct |
18 |
Correct |
139 ms |
14004 KB |
Output is correct |
19 |
Correct |
159 ms |
4932 KB |
Output is correct |
20 |
Correct |
201 ms |
10160 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
187 ms |
11008 KB |
Output is correct |
12 |
Correct |
198 ms |
10068 KB |
Output is correct |
13 |
Correct |
196 ms |
7916 KB |
Output is correct |
14 |
Correct |
185 ms |
8072 KB |
Output is correct |
15 |
Correct |
230 ms |
11264 KB |
Output is correct |
16 |
Correct |
201 ms |
9016 KB |
Output is correct |
17 |
Correct |
216 ms |
8788 KB |
Output is correct |
18 |
Correct |
139 ms |
14004 KB |
Output is correct |
19 |
Correct |
159 ms |
4932 KB |
Output is correct |
20 |
Correct |
201 ms |
10160 KB |
Output is correct |
21 |
Correct |
185 ms |
14172 KB |
Output is correct |
22 |
Correct |
280 ms |
14492 KB |
Output is correct |
23 |
Correct |
228 ms |
11852 KB |
Output is correct |
24 |
Correct |
214 ms |
11152 KB |
Output is correct |
25 |
Correct |
225 ms |
17324 KB |
Output is correct |
26 |
Correct |
249 ms |
12588 KB |
Output is correct |
27 |
Correct |
239 ms |
12624 KB |
Output is correct |
28 |
Correct |
140 ms |
19792 KB |
Output is correct |
29 |
Correct |
178 ms |
11664 KB |
Output is correct |
30 |
Correct |
225 ms |
16212 KB |
Output is correct |
31 |
Correct |
275 ms |
15696 KB |
Output is correct |
32 |
Correct |
254 ms |
15824 KB |
Output is correct |
33 |
Correct |
191 ms |
13596 KB |
Output is correct |
34 |
Correct |
219 ms |
13576 KB |
Output is correct |
35 |
Correct |
257 ms |
14676 KB |
Output is correct |
36 |
Correct |
137 ms |
11728 KB |
Output is correct |
37 |
Correct |
233 ms |
15696 KB |
Output is correct |
38 |
Correct |
190 ms |
11836 KB |
Output is correct |
39 |
Correct |
217 ms |
14116 KB |
Output is correct |
40 |
Correct |
217 ms |
13524 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
31 ms |
6912 KB |
Output is correct |
12 |
Correct |
289 ms |
8176 KB |
Output is correct |
13 |
Correct |
63 ms |
7912 KB |
Output is correct |
14 |
Correct |
55 ms |
7928 KB |
Output is correct |
15 |
Correct |
34 ms |
8184 KB |
Output is correct |
16 |
Correct |
45 ms |
7924 KB |
Output is correct |
17 |
Correct |
57 ms |
7916 KB |
Output is correct |
18 |
Correct |
28 ms |
8176 KB |
Output is correct |
19 |
Correct |
32 ms |
7924 KB |
Output is correct |
20 |
Correct |
33 ms |
7964 KB |
Output is correct |
21 |
Correct |
44 ms |
7992 KB |
Output is correct |
22 |
Correct |
45 ms |
7924 KB |
Output is correct |
23 |
Correct |
32 ms |
7928 KB |
Output is correct |
24 |
Correct |
37 ms |
7924 KB |
Output is correct |
25 |
Correct |
48 ms |
7924 KB |
Output is correct |
26 |
Correct |
29 ms |
7928 KB |
Output is correct |
27 |
Correct |
206 ms |
8100 KB |
Output is correct |
28 |
Correct |
32 ms |
7928 KB |
Output is correct |
29 |
Correct |
35 ms |
7924 KB |
Output is correct |
30 |
Correct |
45 ms |
8140 KB |
Output is correct |
31 |
Correct |
43 ms |
7916 KB |
Output is correct |
32 |
Correct |
43 ms |
7920 KB |
Output is correct |
33 |
Correct |
48 ms |
7928 KB |
Output is correct |
34 |
Correct |
29 ms |
7940 KB |
Output is correct |
35 |
Correct |
56 ms |
7924 KB |
Output is correct |
36 |
Correct |
68 ms |
8020 KB |
Output is correct |
37 |
Correct |
57 ms |
8096 KB |
Output is correct |
38 |
Correct |
56 ms |
7924 KB |
Output is correct |
39 |
Correct |
61 ms |
8172 KB |
Output is correct |
40 |
Correct |
56 ms |
8092 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
187 ms |
11008 KB |
Output is correct |
12 |
Correct |
198 ms |
10068 KB |
Output is correct |
13 |
Correct |
196 ms |
7916 KB |
Output is correct |
14 |
Correct |
185 ms |
8072 KB |
Output is correct |
15 |
Correct |
230 ms |
11264 KB |
Output is correct |
16 |
Correct |
201 ms |
9016 KB |
Output is correct |
17 |
Correct |
216 ms |
8788 KB |
Output is correct |
18 |
Correct |
139 ms |
14004 KB |
Output is correct |
19 |
Correct |
159 ms |
4932 KB |
Output is correct |
20 |
Correct |
201 ms |
10160 KB |
Output is correct |
21 |
Correct |
185 ms |
14172 KB |
Output is correct |
22 |
Correct |
280 ms |
14492 KB |
Output is correct |
23 |
Correct |
228 ms |
11852 KB |
Output is correct |
24 |
Correct |
214 ms |
11152 KB |
Output is correct |
25 |
Correct |
225 ms |
17324 KB |
Output is correct |
26 |
Correct |
249 ms |
12588 KB |
Output is correct |
27 |
Correct |
239 ms |
12624 KB |
Output is correct |
28 |
Correct |
140 ms |
19792 KB |
Output is correct |
29 |
Correct |
178 ms |
11664 KB |
Output is correct |
30 |
Correct |
225 ms |
16212 KB |
Output is correct |
31 |
Correct |
275 ms |
15696 KB |
Output is correct |
32 |
Correct |
254 ms |
15824 KB |
Output is correct |
33 |
Correct |
191 ms |
13596 KB |
Output is correct |
34 |
Correct |
219 ms |
13576 KB |
Output is correct |
35 |
Correct |
257 ms |
14676 KB |
Output is correct |
36 |
Correct |
137 ms |
11728 KB |
Output is correct |
37 |
Correct |
233 ms |
15696 KB |
Output is correct |
38 |
Correct |
190 ms |
11836 KB |
Output is correct |
39 |
Correct |
217 ms |
14116 KB |
Output is correct |
40 |
Correct |
217 ms |
13524 KB |
Output is correct |
41 |
Correct |
31 ms |
6912 KB |
Output is correct |
42 |
Correct |
289 ms |
8176 KB |
Output is correct |
43 |
Correct |
63 ms |
7912 KB |
Output is correct |
44 |
Correct |
55 ms |
7928 KB |
Output is correct |
45 |
Correct |
34 ms |
8184 KB |
Output is correct |
46 |
Correct |
45 ms |
7924 KB |
Output is correct |
47 |
Correct |
57 ms |
7916 KB |
Output is correct |
48 |
Correct |
28 ms |
8176 KB |
Output is correct |
49 |
Correct |
32 ms |
7924 KB |
Output is correct |
50 |
Correct |
33 ms |
7964 KB |
Output is correct |
51 |
Correct |
44 ms |
7992 KB |
Output is correct |
52 |
Correct |
45 ms |
7924 KB |
Output is correct |
53 |
Correct |
32 ms |
7928 KB |
Output is correct |
54 |
Correct |
37 ms |
7924 KB |
Output is correct |
55 |
Correct |
48 ms |
7924 KB |
Output is correct |
56 |
Correct |
29 ms |
7928 KB |
Output is correct |
57 |
Correct |
206 ms |
8100 KB |
Output is correct |
58 |
Correct |
32 ms |
7928 KB |
Output is correct |
59 |
Correct |
35 ms |
7924 KB |
Output is correct |
60 |
Correct |
45 ms |
8140 KB |
Output is correct |
61 |
Correct |
43 ms |
7916 KB |
Output is correct |
62 |
Correct |
43 ms |
7920 KB |
Output is correct |
63 |
Correct |
48 ms |
7928 KB |
Output is correct |
64 |
Correct |
29 ms |
7940 KB |
Output is correct |
65 |
Correct |
56 ms |
7924 KB |
Output is correct |
66 |
Correct |
68 ms |
8020 KB |
Output is correct |
67 |
Correct |
57 ms |
8096 KB |
Output is correct |
68 |
Correct |
56 ms |
7924 KB |
Output is correct |
69 |
Correct |
61 ms |
8172 KB |
Output is correct |
70 |
Correct |
56 ms |
8092 KB |
Output is correct |
71 |
Correct |
319 ms |
32500 KB |
Output is correct |
72 |
Execution timed out |
2033 ms |
16712 KB |
Time limit exceeded |
73 |
Halted |
0 ms |
0 KB |
- |