#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 ll N = 1e6+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][2];
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][(l&1)][1] = sos[i][(l&1)][0] = (s[i]-'0');
repr(j,l-1,0){
bool d = (j&1);
rep(i,0,n){
sos[i][d][0] = sos[i][1-d][0];
sos[i][d][1] = sos[i][1-d][1];
if (i&(1 << j))
sos[i][d][1] += sos[i-(1 << j)][1-d][1];
else
sos[i][d][0] += sos[i+(1 << j)][1-d][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);
if (!t2){
cout << s[mask] << endl;
continue;
}
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 = (__builtin_popcount(i)&1),sum = mask;
rep(j,0,t1){
if ((1 << j)&i) sum -= (1 << ve[j]);
}
if (cnt) ans -= sos[sum][0][1];
else ans += sos[sum][0][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 = (__builtin_popcount(i)&1),sum = mask;
rep(j,0,t0)
if ((1 << j)&i) sum += (1 << ve[j]);
if (cnt) ans -= sos[sum][0][0];
else ans += sos[sum][0][0];
}
cout << ans << endl;
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
324 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 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 |
324 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 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 |
586 ms |
15016 KB |
Output is correct |
12 |
Correct |
640 ms |
14656 KB |
Output is correct |
13 |
Correct |
400 ms |
13976 KB |
Output is correct |
14 |
Correct |
411 ms |
13968 KB |
Output is correct |
15 |
Correct |
1193 ms |
15020 KB |
Output is correct |
16 |
Correct |
601 ms |
14208 KB |
Output is correct |
17 |
Correct |
532 ms |
14168 KB |
Output is correct |
18 |
Correct |
201 ms |
15988 KB |
Output is correct |
19 |
Correct |
201 ms |
12980 KB |
Output is correct |
20 |
Correct |
660 ms |
14664 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
324 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 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 |
586 ms |
15016 KB |
Output is correct |
12 |
Correct |
640 ms |
14656 KB |
Output is correct |
13 |
Correct |
400 ms |
13976 KB |
Output is correct |
14 |
Correct |
411 ms |
13968 KB |
Output is correct |
15 |
Correct |
1193 ms |
15020 KB |
Output is correct |
16 |
Correct |
601 ms |
14208 KB |
Output is correct |
17 |
Correct |
532 ms |
14168 KB |
Output is correct |
18 |
Correct |
201 ms |
15988 KB |
Output is correct |
19 |
Correct |
201 ms |
12980 KB |
Output is correct |
20 |
Correct |
660 ms |
14664 KB |
Output is correct |
21 |
Correct |
272 ms |
18116 KB |
Output is correct |
22 |
Correct |
600 ms |
18308 KB |
Output is correct |
23 |
Correct |
575 ms |
17240 KB |
Output is correct |
24 |
Correct |
529 ms |
17048 KB |
Output is correct |
25 |
Correct |
404 ms |
19092 KB |
Output is correct |
26 |
Correct |
658 ms |
17648 KB |
Output is correct |
27 |
Correct |
626 ms |
17500 KB |
Output is correct |
28 |
Correct |
202 ms |
20144 KB |
Output is correct |
29 |
Correct |
218 ms |
16208 KB |
Output is correct |
30 |
Correct |
542 ms |
18244 KB |
Output is correct |
31 |
Correct |
1064 ms |
18144 KB |
Output is correct |
32 |
Correct |
667 ms |
18100 KB |
Output is correct |
33 |
Correct |
429 ms |
17044 KB |
Output is correct |
34 |
Correct |
500 ms |
17112 KB |
Output is correct |
35 |
Correct |
637 ms |
17676 KB |
Output is correct |
36 |
Correct |
172 ms |
16156 KB |
Output is correct |
37 |
Correct |
1027 ms |
18168 KB |
Output is correct |
38 |
Correct |
233 ms |
16148 KB |
Output is correct |
39 |
Correct |
555 ms |
17424 KB |
Output is correct |
40 |
Correct |
494 ms |
17092 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
324 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 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 |
Runtime error |
26 ms |
35784 KB |
Execution killed with signal 11 |
12 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
324 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 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 |
586 ms |
15016 KB |
Output is correct |
12 |
Correct |
640 ms |
14656 KB |
Output is correct |
13 |
Correct |
400 ms |
13976 KB |
Output is correct |
14 |
Correct |
411 ms |
13968 KB |
Output is correct |
15 |
Correct |
1193 ms |
15020 KB |
Output is correct |
16 |
Correct |
601 ms |
14208 KB |
Output is correct |
17 |
Correct |
532 ms |
14168 KB |
Output is correct |
18 |
Correct |
201 ms |
15988 KB |
Output is correct |
19 |
Correct |
201 ms |
12980 KB |
Output is correct |
20 |
Correct |
660 ms |
14664 KB |
Output is correct |
21 |
Correct |
272 ms |
18116 KB |
Output is correct |
22 |
Correct |
600 ms |
18308 KB |
Output is correct |
23 |
Correct |
575 ms |
17240 KB |
Output is correct |
24 |
Correct |
529 ms |
17048 KB |
Output is correct |
25 |
Correct |
404 ms |
19092 KB |
Output is correct |
26 |
Correct |
658 ms |
17648 KB |
Output is correct |
27 |
Correct |
626 ms |
17500 KB |
Output is correct |
28 |
Correct |
202 ms |
20144 KB |
Output is correct |
29 |
Correct |
218 ms |
16208 KB |
Output is correct |
30 |
Correct |
542 ms |
18244 KB |
Output is correct |
31 |
Correct |
1064 ms |
18144 KB |
Output is correct |
32 |
Correct |
667 ms |
18100 KB |
Output is correct |
33 |
Correct |
429 ms |
17044 KB |
Output is correct |
34 |
Correct |
500 ms |
17112 KB |
Output is correct |
35 |
Correct |
637 ms |
17676 KB |
Output is correct |
36 |
Correct |
172 ms |
16156 KB |
Output is correct |
37 |
Correct |
1027 ms |
18168 KB |
Output is correct |
38 |
Correct |
233 ms |
16148 KB |
Output is correct |
39 |
Correct |
555 ms |
17424 KB |
Output is correct |
40 |
Correct |
494 ms |
17092 KB |
Output is correct |
41 |
Runtime error |
26 ms |
35784 KB |
Execution killed with signal 11 |
42 |
Halted |
0 ms |
0 KB |
- |