#include <bits/stdc++.h>
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#pragma GCC optimize("unroll-loops")
#define rep(i,l,r) for (int i = l; i < r; i++)
#define repr(i,r,l) for (int i = r; i >= l; i--)
#define X first
#define Y second
#define pb push_back
#define endl '\n'
#define debug(x) cerr << #x << " : " << x << endl;
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pll;
constexpr int N = 2e6+20,mod = 1e9+7,inf = 1e9+10,maxm = 1e6;
inline int mkay(int a,int b){
if (a+b >= mod) return a+b-mod;
if (a+b < 0) return a+b+mod;
return a+b;
}
inline int poww(int a,int k){
if (k < 0) return 0;
int z = 1;
while (k){
if (k&1) z = 1ll*z*a%mod;
a = 1ll*a*a%mod;
k >>= 1;
}
return z;
}
int sos[N][2];
ll pw[40];
int main(){
ios :: sync_with_stdio(0); cin.tie(0);
int l,q;
cin >> l >> q;
string s;
cin >> s;
int n = s.size();
rep(i,0,n)
sos[i][1] = sos[i][0] = (s[i]-'0');
repr(j,l-1,0)
repr(i,n-1,0)
if (i&(1 << j))
sos[i][1] += sos[i-(1 << j)][1];
repr(j,l-1,0){
rep(i,0,n){
if ((i&(1 << j)) == 0)
sos[i][0] += sos[i+(1 << j)][0];
}
}
while (q--){
string t;
cin >> t;
reverse(t.begin(),t.end());
int t0 = 0,t2 = 0,t1 = 0,mask = 0;
vector<int> ve;
rep(i,0,l){
if (t[i] == '1'){
t1++;
mask += (1 << i);
}
else if (t[i] == '0') t0++;
else
t2++;
}
if (t2 < 7){
rep(i,0,l) if (t[i] == '?') ve.pb(i);
int y = (1 << t2);
int ans = 0;
rep(j,0,y){
int sum = mask;
rep(k,0,t2)
if (j&(1 << k))
sum += (1 << ve[k]);
ans += (s[sum]-'0');
}
cout << ans << endl;
continue;
}
if (t1 <= t0){
rep(i,0,l){
if (t[i] == '1') ve.pb(i);
if (t[i] == '?') mask += (1 << i);
}
int y = (1 << t1),ans = 0;
rep(i,0,y){
int cnt = 0,sum = mask;
rep(j,0,t1){
if ((1 << j)&i){
sum -= (1 << ve[j]);
cnt ^= 1;
}
}
if (cnt) ans -= sos[sum][1];
else ans += sos[sum][1];
}
cout << ans << endl;
continue;
}
rep(i,0,l)
if (t[i] == '0')
ve.pb(i);
int y = (1 << t0),ans = 0;
rep(i,0,y){
int cnt = 0,sum = mask;
rep(j,0,t0)
if ((1 << j)&i){
sum += (1 << ve[j]);
cnt ^= 1;
}
if (cnt) ans -= sos[sum][0];
else ans += sos[sum][0];
}
cout << ans << endl;
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
2 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
2 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
665 ms |
4300 KB |
Output is correct |
12 |
Correct |
612 ms |
3956 KB |
Output is correct |
13 |
Correct |
365 ms |
3144 KB |
Output is correct |
14 |
Correct |
401 ms |
3272 KB |
Output is correct |
15 |
Correct |
1048 ms |
4380 KB |
Output is correct |
16 |
Correct |
502 ms |
3420 KB |
Output is correct |
17 |
Correct |
531 ms |
3388 KB |
Output is correct |
18 |
Correct |
183 ms |
5336 KB |
Output is correct |
19 |
Correct |
217 ms |
2320 KB |
Output is correct |
20 |
Correct |
611 ms |
3992 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
2 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
665 ms |
4300 KB |
Output is correct |
12 |
Correct |
612 ms |
3956 KB |
Output is correct |
13 |
Correct |
365 ms |
3144 KB |
Output is correct |
14 |
Correct |
401 ms |
3272 KB |
Output is correct |
15 |
Correct |
1048 ms |
4380 KB |
Output is correct |
16 |
Correct |
502 ms |
3420 KB |
Output is correct |
17 |
Correct |
531 ms |
3388 KB |
Output is correct |
18 |
Correct |
183 ms |
5336 KB |
Output is correct |
19 |
Correct |
217 ms |
2320 KB |
Output is correct |
20 |
Correct |
611 ms |
3992 KB |
Output is correct |
21 |
Correct |
235 ms |
4328 KB |
Output is correct |
22 |
Correct |
599 ms |
4520 KB |
Output is correct |
23 |
Correct |
561 ms |
3576 KB |
Output is correct |
24 |
Correct |
568 ms |
3408 KB |
Output is correct |
25 |
Correct |
369 ms |
5368 KB |
Output is correct |
26 |
Correct |
699 ms |
3840 KB |
Output is correct |
27 |
Correct |
699 ms |
3828 KB |
Output is correct |
28 |
Correct |
196 ms |
6340 KB |
Output is correct |
29 |
Correct |
244 ms |
2372 KB |
Output is correct |
30 |
Correct |
538 ms |
4568 KB |
Output is correct |
31 |
Correct |
1136 ms |
4400 KB |
Output is correct |
32 |
Correct |
734 ms |
4412 KB |
Output is correct |
33 |
Correct |
454 ms |
3232 KB |
Output is correct |
34 |
Correct |
587 ms |
3392 KB |
Output is correct |
35 |
Correct |
637 ms |
3824 KB |
Output is correct |
36 |
Correct |
181 ms |
2300 KB |
Output is correct |
37 |
Correct |
1125 ms |
4308 KB |
Output is correct |
38 |
Correct |
260 ms |
2456 KB |
Output is correct |
39 |
Correct |
568 ms |
3480 KB |
Output is correct |
40 |
Correct |
526 ms |
3336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
2 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
76 ms |
9808 KB |
Output is correct |
12 |
Correct |
65 ms |
9816 KB |
Output is correct |
13 |
Correct |
84 ms |
9820 KB |
Output is correct |
14 |
Correct |
113 ms |
9820 KB |
Output is correct |
15 |
Correct |
73 ms |
9936 KB |
Output is correct |
16 |
Correct |
113 ms |
9816 KB |
Output is correct |
17 |
Correct |
93 ms |
9828 KB |
Output is correct |
18 |
Correct |
54 ms |
10060 KB |
Output is correct |
19 |
Correct |
64 ms |
9728 KB |
Output is correct |
20 |
Correct |
85 ms |
9816 KB |
Output is correct |
21 |
Correct |
89 ms |
9796 KB |
Output is correct |
22 |
Correct |
106 ms |
9848 KB |
Output is correct |
23 |
Correct |
72 ms |
9812 KB |
Output is correct |
24 |
Correct |
107 ms |
9816 KB |
Output is correct |
25 |
Correct |
108 ms |
9804 KB |
Output is correct |
26 |
Correct |
53 ms |
9816 KB |
Output is correct |
27 |
Correct |
61 ms |
9804 KB |
Output is correct |
28 |
Correct |
55 ms |
9696 KB |
Output is correct |
29 |
Correct |
80 ms |
9828 KB |
Output is correct |
30 |
Correct |
111 ms |
9860 KB |
Output is correct |
31 |
Correct |
77 ms |
9816 KB |
Output is correct |
32 |
Correct |
110 ms |
9816 KB |
Output is correct |
33 |
Correct |
92 ms |
9828 KB |
Output is correct |
34 |
Correct |
52 ms |
9740 KB |
Output is correct |
35 |
Correct |
82 ms |
9828 KB |
Output is correct |
36 |
Correct |
86 ms |
9816 KB |
Output is correct |
37 |
Correct |
104 ms |
9804 KB |
Output is correct |
38 |
Correct |
91 ms |
9804 KB |
Output is correct |
39 |
Correct |
81 ms |
9816 KB |
Output is correct |
40 |
Correct |
81 ms |
9816 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
2 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
665 ms |
4300 KB |
Output is correct |
12 |
Correct |
612 ms |
3956 KB |
Output is correct |
13 |
Correct |
365 ms |
3144 KB |
Output is correct |
14 |
Correct |
401 ms |
3272 KB |
Output is correct |
15 |
Correct |
1048 ms |
4380 KB |
Output is correct |
16 |
Correct |
502 ms |
3420 KB |
Output is correct |
17 |
Correct |
531 ms |
3388 KB |
Output is correct |
18 |
Correct |
183 ms |
5336 KB |
Output is correct |
19 |
Correct |
217 ms |
2320 KB |
Output is correct |
20 |
Correct |
611 ms |
3992 KB |
Output is correct |
21 |
Correct |
235 ms |
4328 KB |
Output is correct |
22 |
Correct |
599 ms |
4520 KB |
Output is correct |
23 |
Correct |
561 ms |
3576 KB |
Output is correct |
24 |
Correct |
568 ms |
3408 KB |
Output is correct |
25 |
Correct |
369 ms |
5368 KB |
Output is correct |
26 |
Correct |
699 ms |
3840 KB |
Output is correct |
27 |
Correct |
699 ms |
3828 KB |
Output is correct |
28 |
Correct |
196 ms |
6340 KB |
Output is correct |
29 |
Correct |
244 ms |
2372 KB |
Output is correct |
30 |
Correct |
538 ms |
4568 KB |
Output is correct |
31 |
Correct |
1136 ms |
4400 KB |
Output is correct |
32 |
Correct |
734 ms |
4412 KB |
Output is correct |
33 |
Correct |
454 ms |
3232 KB |
Output is correct |
34 |
Correct |
587 ms |
3392 KB |
Output is correct |
35 |
Correct |
637 ms |
3824 KB |
Output is correct |
36 |
Correct |
181 ms |
2300 KB |
Output is correct |
37 |
Correct |
1125 ms |
4308 KB |
Output is correct |
38 |
Correct |
260 ms |
2456 KB |
Output is correct |
39 |
Correct |
568 ms |
3480 KB |
Output is correct |
40 |
Correct |
526 ms |
3336 KB |
Output is correct |
41 |
Correct |
76 ms |
9808 KB |
Output is correct |
42 |
Correct |
65 ms |
9816 KB |
Output is correct |
43 |
Correct |
84 ms |
9820 KB |
Output is correct |
44 |
Correct |
113 ms |
9820 KB |
Output is correct |
45 |
Correct |
73 ms |
9936 KB |
Output is correct |
46 |
Correct |
113 ms |
9816 KB |
Output is correct |
47 |
Correct |
93 ms |
9828 KB |
Output is correct |
48 |
Correct |
54 ms |
10060 KB |
Output is correct |
49 |
Correct |
64 ms |
9728 KB |
Output is correct |
50 |
Correct |
85 ms |
9816 KB |
Output is correct |
51 |
Correct |
89 ms |
9796 KB |
Output is correct |
52 |
Correct |
106 ms |
9848 KB |
Output is correct |
53 |
Correct |
72 ms |
9812 KB |
Output is correct |
54 |
Correct |
107 ms |
9816 KB |
Output is correct |
55 |
Correct |
108 ms |
9804 KB |
Output is correct |
56 |
Correct |
53 ms |
9816 KB |
Output is correct |
57 |
Correct |
61 ms |
9804 KB |
Output is correct |
58 |
Correct |
55 ms |
9696 KB |
Output is correct |
59 |
Correct |
80 ms |
9828 KB |
Output is correct |
60 |
Correct |
111 ms |
9860 KB |
Output is correct |
61 |
Correct |
77 ms |
9816 KB |
Output is correct |
62 |
Correct |
110 ms |
9816 KB |
Output is correct |
63 |
Correct |
92 ms |
9828 KB |
Output is correct |
64 |
Correct |
52 ms |
9740 KB |
Output is correct |
65 |
Correct |
82 ms |
9828 KB |
Output is correct |
66 |
Correct |
86 ms |
9816 KB |
Output is correct |
67 |
Correct |
104 ms |
9804 KB |
Output is correct |
68 |
Correct |
91 ms |
9804 KB |
Output is correct |
69 |
Correct |
81 ms |
9816 KB |
Output is correct |
70 |
Correct |
81 ms |
9816 KB |
Output is correct |
71 |
Correct |
524 ms |
14692 KB |
Output is correct |
72 |
Correct |
673 ms |
14916 KB |
Output is correct |
73 |
Correct |
1014 ms |
13412 KB |
Output is correct |
74 |
Correct |
1696 ms |
15304 KB |
Output is correct |
75 |
Correct |
664 ms |
37268 KB |
Output is correct |
76 |
Correct |
1523 ms |
35548 KB |
Output is correct |
77 |
Correct |
1290 ms |
35488 KB |
Output is correct |
78 |
Correct |
320 ms |
39276 KB |
Output is correct |
79 |
Correct |
470 ms |
33168 KB |
Output is correct |
80 |
Correct |
552 ms |
36304 KB |
Output is correct |
81 |
Correct |
951 ms |
36284 KB |
Output is correct |
82 |
Correct |
1621 ms |
35260 KB |
Output is correct |
83 |
Correct |
787 ms |
34448 KB |
Output is correct |
84 |
Correct |
1366 ms |
35372 KB |
Output is correct |
85 |
Correct |
1266 ms |
35496 KB |
Output is correct |
86 |
Correct |
355 ms |
33244 KB |
Output is correct |
87 |
Correct |
560 ms |
36216 KB |
Output is correct |
88 |
Correct |
400 ms |
33228 KB |
Output is correct |
89 |
Correct |
905 ms |
35052 KB |
Output is correct |
90 |
Correct |
1279 ms |
35400 KB |
Output is correct |
91 |
Correct |
688 ms |
34372 KB |
Output is correct |
92 |
Correct |
1390 ms |
35712 KB |
Output is correct |
93 |
Correct |
1147 ms |
35572 KB |
Output is correct |
94 |
Correct |
318 ms |
33184 KB |
Output is correct |
95 |
Correct |
981 ms |
35488 KB |
Output is correct |
96 |
Correct |
1000 ms |
35264 KB |
Output is correct |
97 |
Correct |
1032 ms |
35368 KB |
Output is correct |
98 |
Correct |
969 ms |
35360 KB |
Output is correct |
99 |
Correct |
954 ms |
35400 KB |
Output is correct |
100 |
Correct |
963 ms |
35408 KB |
Output is correct |