#include <bits/stdc++.h>
using namespace std;
int a[1048580], b[1048580], c[1048580];
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, m;
cin >> n >> m;
for (int i=0; i<(1<<n); i++)
{
char x;
cin >> x;
a[i]=b[i]=c[i^((1<<n)-1)]=x-'0';
}
for (int i=0; i<n; i++)
for (int j=0; j<(1<<n); j++)
if (j&(1<<i))
b[j]+=b[j^(1<<i)], c[j]+=c[j^(1<<i)];
for (int i=0; i<m; i++)
{
string s;
cin >> s;
reverse(s.begin(), s.end());
vector<int> v0, v1, v2;
for (int j=0; j<n; j++)
{
if (s[j]=='0')
v0.push_back(j);
else if (s[j]=='1')
v1.push_back(j);
else
v2.push_back(j);
}
if (v0.size()<=v1.size() && v0.size()<=v2.size())
{
int x=0, sz=v0.size(), ans=0;
for (int j=0; j<n; j++)
if (s[j]=='0' || s[j]=='?')
x^=(1<<j);
for (int j=0; j<(1<<sz); j++)
{
int y=0, cnt=0;
for (int k=0; k<sz; k++)
{
if (j&(1<<k))
{
y^=(1<<v0[k]);
cnt++;
}
}
if (cnt&1)
ans-=c[x^y];
else
ans+=c[x^y];
}
cout << ans << '\n';
}
else if (v1.size()<=v0.size() && v1.size()<=v2.size())
{
int x=0, sz=v1.size(), ans=0;
for (int j=0; j<n; j++)
if (s[j]=='1' || s[j]=='?')
x^=(1<<j);
for (int j=0; j<(1<<sz); j++)
{
int y=0, cnt=0;
for (int k=0; k<sz; k++)
{
if (j&(1<<k))
{
y^=(1<<v1[k]);
cnt++;
}
}
if (cnt&1)
ans-=b[x^y];
else
ans+=b[x^y];
}
cout << ans << '\n';
}
else
{
int x=0, sz=v2.size(), ans=0;
for (int j=0; j<n; j++)
if (s[j]=='1')
x^=(1<<j);
for (int j=0; j<(1<<sz); j++)
{
int y=0;
for (int k=0; k<sz; k++)
if (j&(1<<k))
y^=(1<<v2[k]);
ans+=a[x^y];
}
cout << ans << '\n';
}
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 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 |
348 KB |
Output is correct |
3 |
Correct |
1 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 |
312 ms |
15184 KB |
Output is correct |
12 |
Correct |
310 ms |
14676 KB |
Output is correct |
13 |
Correct |
381 ms |
13904 KB |
Output is correct |
14 |
Correct |
430 ms |
14160 KB |
Output is correct |
15 |
Correct |
392 ms |
15196 KB |
Output is correct |
16 |
Correct |
425 ms |
14180 KB |
Output is correct |
17 |
Correct |
437 ms |
14160 KB |
Output is correct |
18 |
Correct |
212 ms |
16212 KB |
Output is correct |
19 |
Correct |
340 ms |
13104 KB |
Output is correct |
20 |
Correct |
327 ms |
14668 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 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 |
312 ms |
15184 KB |
Output is correct |
12 |
Correct |
310 ms |
14676 KB |
Output is correct |
13 |
Correct |
381 ms |
13904 KB |
Output is correct |
14 |
Correct |
430 ms |
14160 KB |
Output is correct |
15 |
Correct |
392 ms |
15196 KB |
Output is correct |
16 |
Correct |
425 ms |
14180 KB |
Output is correct |
17 |
Correct |
437 ms |
14160 KB |
Output is correct |
18 |
Correct |
212 ms |
16212 KB |
Output is correct |
19 |
Correct |
340 ms |
13104 KB |
Output is correct |
20 |
Correct |
327 ms |
14668 KB |
Output is correct |
21 |
Correct |
386 ms |
18260 KB |
Output is correct |
22 |
Correct |
400 ms |
18260 KB |
Output is correct |
23 |
Correct |
488 ms |
17488 KB |
Output is correct |
24 |
Correct |
534 ms |
17236 KB |
Output is correct |
25 |
Correct |
425 ms |
19028 KB |
Output is correct |
26 |
Correct |
536 ms |
17752 KB |
Output is correct |
27 |
Correct |
557 ms |
17748 KB |
Output is correct |
28 |
Correct |
215 ms |
20052 KB |
Output is correct |
29 |
Correct |
371 ms |
16212 KB |
Output is correct |
30 |
Correct |
391 ms |
18260 KB |
Output is correct |
31 |
Correct |
493 ms |
18164 KB |
Output is correct |
32 |
Correct |
558 ms |
18224 KB |
Output is correct |
33 |
Correct |
413 ms |
16976 KB |
Output is correct |
34 |
Correct |
541 ms |
17236 KB |
Output is correct |
35 |
Correct |
533 ms |
17536 KB |
Output is correct |
36 |
Correct |
206 ms |
16212 KB |
Output is correct |
37 |
Correct |
361 ms |
18048 KB |
Output is correct |
38 |
Correct |
379 ms |
16204 KB |
Output is correct |
39 |
Correct |
493 ms |
17232 KB |
Output is correct |
40 |
Correct |
546 ms |
17152 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 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 |
55 ms |
14824 KB |
Output is correct |
12 |
Correct |
55 ms |
14928 KB |
Output is correct |
13 |
Correct |
72 ms |
14736 KB |
Output is correct |
14 |
Correct |
90 ms |
14792 KB |
Output is correct |
15 |
Correct |
59 ms |
14932 KB |
Output is correct |
16 |
Correct |
83 ms |
14784 KB |
Output is correct |
17 |
Correct |
75 ms |
14932 KB |
Output is correct |
18 |
Correct |
41 ms |
15184 KB |
Output is correct |
19 |
Correct |
54 ms |
14672 KB |
Output is correct |
20 |
Correct |
55 ms |
14932 KB |
Output is correct |
21 |
Correct |
67 ms |
14932 KB |
Output is correct |
22 |
Correct |
87 ms |
14988 KB |
Output is correct |
23 |
Correct |
57 ms |
14928 KB |
Output is correct |
24 |
Correct |
84 ms |
14928 KB |
Output is correct |
25 |
Correct |
83 ms |
14940 KB |
Output is correct |
26 |
Correct |
43 ms |
14672 KB |
Output is correct |
27 |
Correct |
55 ms |
14832 KB |
Output is correct |
28 |
Correct |
55 ms |
14676 KB |
Output is correct |
29 |
Correct |
66 ms |
14928 KB |
Output is correct |
30 |
Correct |
82 ms |
14788 KB |
Output is correct |
31 |
Correct |
57 ms |
14792 KB |
Output is correct |
32 |
Correct |
91 ms |
14928 KB |
Output is correct |
33 |
Correct |
78 ms |
14932 KB |
Output is correct |
34 |
Correct |
40 ms |
14852 KB |
Output is correct |
35 |
Correct |
67 ms |
14928 KB |
Output is correct |
36 |
Correct |
68 ms |
15000 KB |
Output is correct |
37 |
Correct |
72 ms |
14792 KB |
Output is correct |
38 |
Correct |
71 ms |
14928 KB |
Output is correct |
39 |
Correct |
69 ms |
15184 KB |
Output is correct |
40 |
Correct |
71 ms |
14928 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 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 |
312 ms |
15184 KB |
Output is correct |
12 |
Correct |
310 ms |
14676 KB |
Output is correct |
13 |
Correct |
381 ms |
13904 KB |
Output is correct |
14 |
Correct |
430 ms |
14160 KB |
Output is correct |
15 |
Correct |
392 ms |
15196 KB |
Output is correct |
16 |
Correct |
425 ms |
14180 KB |
Output is correct |
17 |
Correct |
437 ms |
14160 KB |
Output is correct |
18 |
Correct |
212 ms |
16212 KB |
Output is correct |
19 |
Correct |
340 ms |
13104 KB |
Output is correct |
20 |
Correct |
327 ms |
14668 KB |
Output is correct |
21 |
Correct |
386 ms |
18260 KB |
Output is correct |
22 |
Correct |
400 ms |
18260 KB |
Output is correct |
23 |
Correct |
488 ms |
17488 KB |
Output is correct |
24 |
Correct |
534 ms |
17236 KB |
Output is correct |
25 |
Correct |
425 ms |
19028 KB |
Output is correct |
26 |
Correct |
536 ms |
17752 KB |
Output is correct |
27 |
Correct |
557 ms |
17748 KB |
Output is correct |
28 |
Correct |
215 ms |
20052 KB |
Output is correct |
29 |
Correct |
371 ms |
16212 KB |
Output is correct |
30 |
Correct |
391 ms |
18260 KB |
Output is correct |
31 |
Correct |
493 ms |
18164 KB |
Output is correct |
32 |
Correct |
558 ms |
18224 KB |
Output is correct |
33 |
Correct |
413 ms |
16976 KB |
Output is correct |
34 |
Correct |
541 ms |
17236 KB |
Output is correct |
35 |
Correct |
533 ms |
17536 KB |
Output is correct |
36 |
Correct |
206 ms |
16212 KB |
Output is correct |
37 |
Correct |
361 ms |
18048 KB |
Output is correct |
38 |
Correct |
379 ms |
16204 KB |
Output is correct |
39 |
Correct |
493 ms |
17232 KB |
Output is correct |
40 |
Correct |
546 ms |
17152 KB |
Output is correct |
41 |
Correct |
55 ms |
14824 KB |
Output is correct |
42 |
Correct |
55 ms |
14928 KB |
Output is correct |
43 |
Correct |
72 ms |
14736 KB |
Output is correct |
44 |
Correct |
90 ms |
14792 KB |
Output is correct |
45 |
Correct |
59 ms |
14932 KB |
Output is correct |
46 |
Correct |
83 ms |
14784 KB |
Output is correct |
47 |
Correct |
75 ms |
14932 KB |
Output is correct |
48 |
Correct |
41 ms |
15184 KB |
Output is correct |
49 |
Correct |
54 ms |
14672 KB |
Output is correct |
50 |
Correct |
55 ms |
14932 KB |
Output is correct |
51 |
Correct |
67 ms |
14932 KB |
Output is correct |
52 |
Correct |
87 ms |
14988 KB |
Output is correct |
53 |
Correct |
57 ms |
14928 KB |
Output is correct |
54 |
Correct |
84 ms |
14928 KB |
Output is correct |
55 |
Correct |
83 ms |
14940 KB |
Output is correct |
56 |
Correct |
43 ms |
14672 KB |
Output is correct |
57 |
Correct |
55 ms |
14832 KB |
Output is correct |
58 |
Correct |
55 ms |
14676 KB |
Output is correct |
59 |
Correct |
66 ms |
14928 KB |
Output is correct |
60 |
Correct |
82 ms |
14788 KB |
Output is correct |
61 |
Correct |
57 ms |
14792 KB |
Output is correct |
62 |
Correct |
91 ms |
14928 KB |
Output is correct |
63 |
Correct |
78 ms |
14932 KB |
Output is correct |
64 |
Correct |
40 ms |
14852 KB |
Output is correct |
65 |
Correct |
67 ms |
14928 KB |
Output is correct |
66 |
Correct |
68 ms |
15000 KB |
Output is correct |
67 |
Correct |
72 ms |
14792 KB |
Output is correct |
68 |
Correct |
71 ms |
14928 KB |
Output is correct |
69 |
Correct |
69 ms |
15184 KB |
Output is correct |
70 |
Correct |
71 ms |
14928 KB |
Output is correct |
71 |
Correct |
562 ms |
39252 KB |
Output is correct |
72 |
Correct |
544 ms |
39228 KB |
Output is correct |
73 |
Correct |
834 ms |
37716 KB |
Output is correct |
74 |
Correct |
1263 ms |
38224 KB |
Output is correct |
75 |
Correct |
623 ms |
40276 KB |
Output is correct |
76 |
Correct |
1118 ms |
38552 KB |
Output is correct |
77 |
Correct |
984 ms |
38492 KB |
Output is correct |
78 |
Correct |
344 ms |
42324 KB |
Output is correct |
79 |
Correct |
538 ms |
36296 KB |
Output is correct |
80 |
Correct |
566 ms |
39252 KB |
Output is correct |
81 |
Correct |
806 ms |
39112 KB |
Output is correct |
82 |
Correct |
1201 ms |
38080 KB |
Output is correct |
83 |
Correct |
592 ms |
37488 KB |
Output is correct |
84 |
Correct |
1020 ms |
38276 KB |
Output is correct |
85 |
Correct |
984 ms |
38484 KB |
Output is correct |
86 |
Correct |
289 ms |
36064 KB |
Output is correct |
87 |
Correct |
595 ms |
39248 KB |
Output is correct |
88 |
Correct |
564 ms |
36176 KB |
Output is correct |
89 |
Correct |
766 ms |
37940 KB |
Output is correct |
90 |
Correct |
1051 ms |
38180 KB |
Output is correct |
91 |
Correct |
625 ms |
37324 KB |
Output is correct |
92 |
Correct |
1132 ms |
38524 KB |
Output is correct |
93 |
Correct |
988 ms |
38480 KB |
Output is correct |
94 |
Correct |
291 ms |
36296 KB |
Output is correct |
95 |
Correct |
843 ms |
38272 KB |
Output is correct |
96 |
Correct |
842 ms |
38228 KB |
Output is correct |
97 |
Correct |
850 ms |
38236 KB |
Output is correct |
98 |
Correct |
848 ms |
38224 KB |
Output is correct |
99 |
Correct |
849 ms |
38344 KB |
Output is correct |
100 |
Correct |
832 ms |
38140 KB |
Output is correct |