#include<bits/stdc++.h>
using namespace std;
int dp1[1<<20],dp2[1<<20],orig[1<<20];
void readst(string &str){
char c=getchar();
while(c==' '||c=='\n')
c=getchar();
while(c!=' '&&c!='\n')
str+=c,c=getchar();
}
void brute(string a){
vector<int>can;
int k=0,l=a.size()-1,ans=0;
for(int i=0;i<=l;i++)
if(a[i]=='?') k<<=1,
can.push_back(l-i);
else k<<=1,k+=a[i]-48;
int x=can.size();
for(int i=0;i<1<<x;i++){
int k2=k;
for(int j=0;j<x;j++)
k2|=(i>>j&1)<<can[j];
ans+=orig[k2];
}
cout<<ans<<'\n';
}
void subs(string a){
vector<int>can;
int k=0,l=a.size()-1,ans=0;
for(int i=0;i<=l;i++)
if(a[i]=='?') k=k<<1|1;
else if(a[i]=='0') k<<=1;
else can.push_back(l-i),k=k<<1|1;
int x=can.size();
for(int i=0;i<1<<x;i++){
int k2=k;
for(int j=0;j<x;j++)
k2^=(i>>j&1)<<can[j];
int y=__builtin_popcount(i)%2;
ans+=(-y*2+1)*dp1[k2];
}
cout<<ans<<'\n';
}
void sups(string a){
vector<int>can;
int k=0,l=a.size()-1,ans=0;
for(int i=0;i<=l;i++)
if(a[i]=='?') k<<=1;
else if(a[i]=='1')k=k<<1|1;
else can.push_back(l-i),k<<=1;
int x=can.size();
for(int i=0;i<1<<x;i++){
int k2=k;
for(int j=0;j<x;j++)
k2^=(i>>j&1)<<can[j];
int y=__builtin_popcount(i)%2;
ans+=(-y*2+1)*dp2[k2];
}
cout<<ans<<'\n';
}
int main(){
int n,m;
string str;
cin>>n>>m;
readst(str);
for(int i=0;i<1<<n;i++)
dp1[i]=dp2[i]=orig[i]=str[i]-48;
for(int i=0;i<n;i++) for(int j=0;j<1<<n;j++)
if(j&1<<i) dp1[j]+=dp1[j^1<<i],dp2[j^1<<i]+=dp2[j];
while(m--){
string qr;
readst(qr);
int a=0,b=0,c=0;
for(auto i:qr)
if(i=='0')
a++;
else if(i=='1')
b++;
else c++;
if(c<=6)brute(qr);
else if(b<=6)subs(qr);
else sups(qr);
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
344 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 |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
344 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 |
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 |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
346 ms |
15324 KB |
Output is correct |
12 |
Correct |
331 ms |
14744 KB |
Output is correct |
13 |
Correct |
269 ms |
13904 KB |
Output is correct |
14 |
Correct |
259 ms |
14188 KB |
Output is correct |
15 |
Correct |
577 ms |
15188 KB |
Output is correct |
16 |
Correct |
331 ms |
14372 KB |
Output is correct |
17 |
Correct |
314 ms |
14164 KB |
Output is correct |
18 |
Correct |
116 ms |
16212 KB |
Output is correct |
19 |
Correct |
145 ms |
13088 KB |
Output is correct |
20 |
Correct |
348 ms |
14892 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 |
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 |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
346 ms |
15324 KB |
Output is correct |
12 |
Correct |
331 ms |
14744 KB |
Output is correct |
13 |
Correct |
269 ms |
13904 KB |
Output is correct |
14 |
Correct |
259 ms |
14188 KB |
Output is correct |
15 |
Correct |
577 ms |
15188 KB |
Output is correct |
16 |
Correct |
331 ms |
14372 KB |
Output is correct |
17 |
Correct |
314 ms |
14164 KB |
Output is correct |
18 |
Correct |
116 ms |
16212 KB |
Output is correct |
19 |
Correct |
145 ms |
13088 KB |
Output is correct |
20 |
Correct |
348 ms |
14892 KB |
Output is correct |
21 |
Correct |
695 ms |
18268 KB |
Output is correct |
22 |
Correct |
501 ms |
18300 KB |
Output is correct |
23 |
Correct |
349 ms |
17256 KB |
Output is correct |
24 |
Correct |
354 ms |
17236 KB |
Output is correct |
25 |
Correct |
336 ms |
19288 KB |
Output is correct |
26 |
Correct |
411 ms |
17584 KB |
Output is correct |
27 |
Correct |
460 ms |
17720 KB |
Output is correct |
28 |
Correct |
134 ms |
20264 KB |
Output is correct |
29 |
Correct |
168 ms |
16232 KB |
Output is correct |
30 |
Correct |
502 ms |
18256 KB |
Output is correct |
31 |
Correct |
600 ms |
18096 KB |
Output is correct |
32 |
Correct |
445 ms |
18260 KB |
Output is correct |
33 |
Correct |
263 ms |
17128 KB |
Output is correct |
34 |
Correct |
353 ms |
17236 KB |
Output is correct |
35 |
Correct |
417 ms |
17524 KB |
Output is correct |
36 |
Correct |
119 ms |
16212 KB |
Output is correct |
37 |
Correct |
555 ms |
18256 KB |
Output is correct |
38 |
Correct |
182 ms |
16212 KB |
Output is correct |
39 |
Correct |
337 ms |
17216 KB |
Output is correct |
40 |
Correct |
352 ms |
17236 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 |
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 |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
46 ms |
16196 KB |
Output is correct |
12 |
Correct |
47 ms |
16192 KB |
Output is correct |
13 |
Correct |
60 ms |
16128 KB |
Output is correct |
14 |
Correct |
79 ms |
16076 KB |
Output is correct |
15 |
Correct |
55 ms |
16244 KB |
Output is correct |
16 |
Correct |
72 ms |
15944 KB |
Output is correct |
17 |
Correct |
74 ms |
15936 KB |
Output is correct |
18 |
Correct |
39 ms |
16224 KB |
Output is correct |
19 |
Correct |
44 ms |
15940 KB |
Output is correct |
20 |
Correct |
50 ms |
16120 KB |
Output is correct |
21 |
Correct |
66 ms |
16196 KB |
Output is correct |
22 |
Correct |
82 ms |
16324 KB |
Output is correct |
23 |
Correct |
50 ms |
15936 KB |
Output is correct |
24 |
Correct |
71 ms |
16040 KB |
Output is correct |
25 |
Correct |
69 ms |
15948 KB |
Output is correct |
26 |
Correct |
37 ms |
15940 KB |
Output is correct |
27 |
Correct |
47 ms |
16192 KB |
Output is correct |
28 |
Correct |
53 ms |
15940 KB |
Output is correct |
29 |
Correct |
60 ms |
16028 KB |
Output is correct |
30 |
Correct |
73 ms |
16132 KB |
Output is correct |
31 |
Correct |
52 ms |
15960 KB |
Output is correct |
32 |
Correct |
77 ms |
15944 KB |
Output is correct |
33 |
Correct |
69 ms |
15936 KB |
Output is correct |
34 |
Correct |
40 ms |
15936 KB |
Output is correct |
35 |
Correct |
62 ms |
15936 KB |
Output is correct |
36 |
Correct |
69 ms |
16256 KB |
Output is correct |
37 |
Correct |
60 ms |
15936 KB |
Output is correct |
38 |
Correct |
60 ms |
15932 KB |
Output is correct |
39 |
Correct |
63 ms |
15932 KB |
Output is correct |
40 |
Correct |
66 ms |
15940 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 |
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 |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
346 ms |
15324 KB |
Output is correct |
12 |
Correct |
331 ms |
14744 KB |
Output is correct |
13 |
Correct |
269 ms |
13904 KB |
Output is correct |
14 |
Correct |
259 ms |
14188 KB |
Output is correct |
15 |
Correct |
577 ms |
15188 KB |
Output is correct |
16 |
Correct |
331 ms |
14372 KB |
Output is correct |
17 |
Correct |
314 ms |
14164 KB |
Output is correct |
18 |
Correct |
116 ms |
16212 KB |
Output is correct |
19 |
Correct |
145 ms |
13088 KB |
Output is correct |
20 |
Correct |
348 ms |
14892 KB |
Output is correct |
21 |
Correct |
695 ms |
18268 KB |
Output is correct |
22 |
Correct |
501 ms |
18300 KB |
Output is correct |
23 |
Correct |
349 ms |
17256 KB |
Output is correct |
24 |
Correct |
354 ms |
17236 KB |
Output is correct |
25 |
Correct |
336 ms |
19288 KB |
Output is correct |
26 |
Correct |
411 ms |
17584 KB |
Output is correct |
27 |
Correct |
460 ms |
17720 KB |
Output is correct |
28 |
Correct |
134 ms |
20264 KB |
Output is correct |
29 |
Correct |
168 ms |
16232 KB |
Output is correct |
30 |
Correct |
502 ms |
18256 KB |
Output is correct |
31 |
Correct |
600 ms |
18096 KB |
Output is correct |
32 |
Correct |
445 ms |
18260 KB |
Output is correct |
33 |
Correct |
263 ms |
17128 KB |
Output is correct |
34 |
Correct |
353 ms |
17236 KB |
Output is correct |
35 |
Correct |
417 ms |
17524 KB |
Output is correct |
36 |
Correct |
119 ms |
16212 KB |
Output is correct |
37 |
Correct |
555 ms |
18256 KB |
Output is correct |
38 |
Correct |
182 ms |
16212 KB |
Output is correct |
39 |
Correct |
337 ms |
17216 KB |
Output is correct |
40 |
Correct |
352 ms |
17236 KB |
Output is correct |
41 |
Correct |
46 ms |
16196 KB |
Output is correct |
42 |
Correct |
47 ms |
16192 KB |
Output is correct |
43 |
Correct |
60 ms |
16128 KB |
Output is correct |
44 |
Correct |
79 ms |
16076 KB |
Output is correct |
45 |
Correct |
55 ms |
16244 KB |
Output is correct |
46 |
Correct |
72 ms |
15944 KB |
Output is correct |
47 |
Correct |
74 ms |
15936 KB |
Output is correct |
48 |
Correct |
39 ms |
16224 KB |
Output is correct |
49 |
Correct |
44 ms |
15940 KB |
Output is correct |
50 |
Correct |
50 ms |
16120 KB |
Output is correct |
51 |
Correct |
66 ms |
16196 KB |
Output is correct |
52 |
Correct |
82 ms |
16324 KB |
Output is correct |
53 |
Correct |
50 ms |
15936 KB |
Output is correct |
54 |
Correct |
71 ms |
16040 KB |
Output is correct |
55 |
Correct |
69 ms |
15948 KB |
Output is correct |
56 |
Correct |
37 ms |
15940 KB |
Output is correct |
57 |
Correct |
47 ms |
16192 KB |
Output is correct |
58 |
Correct |
53 ms |
15940 KB |
Output is correct |
59 |
Correct |
60 ms |
16028 KB |
Output is correct |
60 |
Correct |
73 ms |
16132 KB |
Output is correct |
61 |
Correct |
52 ms |
15960 KB |
Output is correct |
62 |
Correct |
77 ms |
15944 KB |
Output is correct |
63 |
Correct |
69 ms |
15936 KB |
Output is correct |
64 |
Correct |
40 ms |
15936 KB |
Output is correct |
65 |
Correct |
62 ms |
15936 KB |
Output is correct |
66 |
Correct |
69 ms |
16256 KB |
Output is correct |
67 |
Correct |
60 ms |
15936 KB |
Output is correct |
68 |
Correct |
60 ms |
15932 KB |
Output is correct |
69 |
Correct |
63 ms |
15932 KB |
Output is correct |
70 |
Correct |
66 ms |
15940 KB |
Output is correct |
71 |
Correct |
367 ms |
40428 KB |
Output is correct |
72 |
Correct |
439 ms |
40552 KB |
Output is correct |
73 |
Correct |
613 ms |
39048 KB |
Output is correct |
74 |
Correct |
1097 ms |
39408 KB |
Output is correct |
75 |
Correct |
568 ms |
41408 KB |
Output is correct |
76 |
Correct |
846 ms |
39740 KB |
Output is correct |
77 |
Correct |
763 ms |
39628 KB |
Output is correct |
78 |
Correct |
227 ms |
43320 KB |
Output is correct |
79 |
Correct |
282 ms |
37436 KB |
Output is correct |
80 |
Correct |
421 ms |
40440 KB |
Output is correct |
81 |
Correct |
664 ms |
40392 KB |
Output is correct |
82 |
Correct |
930 ms |
39400 KB |
Output is correct |
83 |
Correct |
445 ms |
38472 KB |
Output is correct |
84 |
Correct |
745 ms |
39492 KB |
Output is correct |
85 |
Correct |
695 ms |
39496 KB |
Output is correct |
86 |
Correct |
199 ms |
37384 KB |
Output is correct |
87 |
Correct |
355 ms |
40580 KB |
Output is correct |
88 |
Correct |
302 ms |
37396 KB |
Output is correct |
89 |
Correct |
605 ms |
38948 KB |
Output is correct |
90 |
Correct |
861 ms |
39432 KB |
Output is correct |
91 |
Correct |
508 ms |
38460 KB |
Output is correct |
92 |
Correct |
964 ms |
39740 KB |
Output is correct |
93 |
Correct |
782 ms |
39648 KB |
Output is correct |
94 |
Correct |
221 ms |
37612 KB |
Output is correct |
95 |
Correct |
624 ms |
39488 KB |
Output is correct |
96 |
Correct |
663 ms |
39488 KB |
Output is correct |
97 |
Correct |
665 ms |
39452 KB |
Output is correct |
98 |
Correct |
670 ms |
39484 KB |
Output is correct |
99 |
Correct |
686 ms |
39488 KB |
Output is correct |
100 |
Correct |
663 ms |
39492 KB |
Output is correct |