#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ll, int> li;
#define FOR(i, a, b) for(int i = a; i < b; i++)
#define ROF(i, a, b) for(int i = a; i >= b; i--)
#define ms memset
#define pb push_back
#define fi first
#define se second
int main(){
ios::sync_with_stdio(false);
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
int L, Q; cin>>L>>Q;
string s; cin >> s;
int dp[1<<L]; FOR(i,0,(1<<L)) dp[i]=s[i]-'0';
int dp2[1<<L]; FOR(i,0,(1<<L)) dp2[i]=s[(1<<L)-1-i]-'0';
FOR(i,0,L){
FOR(mask,0,(1<<L)){
if (mask & (1<<i)) {dp[mask] += dp[mask-(1<<i)]; dp2[mask] += dp2[mask-(1<<i)];}
}
}
FOR(i,0,Q){
string t; cin >> t; reverse(t.begin(), t.end());
int cnt1=0, cnt2=0; FOR(j,0,L) {cnt1 += (t[j]=='?'); cnt2 += (t[j]=='1');}
if (cnt1 <= 6){
int ans = 0;
vi a; int cur = 0;
FOR(j,0,L){
if (t[j]=='?') a.pb(j);
else cur += (1<<j)*(t[j]-'0');
}
FOR(j,0,(1<<cnt1)){
int val=0; FOR(k,0,cnt1){
if (j & (1<<k)) val += (1<<a[k]);
}
//cout<<cur+val<<" ";
ans+=s[cur+val]-'0';
}
cout<<ans<<'\n'; continue;
}
if (cnt2 <= 6){
vi a; int cur=0;
FOR(j,0,L){
if (t[j]=='1') {a.pb(j); cur += (1<<j);}
if (t[j]=='?') cur += (1<<j);
}
int ans = 0;
FOR(j,0,(1<<cnt2)){
int val=0; int num=0; FOR(k,0,cnt2){
if (j & (1<<k)) {val += (1<<a[k]); num=1-num;}
}
if (num % 2 == 0) ans += dp[cur-val];
else ans -= dp[cur-val];
}
cout<<ans<<'\n'; continue;
}
int cnt3=L-cnt1-cnt2; vi a; int cur=0;
FOR(j,0,L){
if (t[j] != '1') cur+= (1<<j);
if (t[j] == '0') a.pb(j);
}
int ans=0;
FOR(j,0,(1<<cnt3)){
int val=0,num=0; FOR(k,0,cnt3){
if (j & (1<<k)) {val += (1<<a[k]); num=1-num;}
}
if (num) ans-=dp2[cur-val];
else ans+=dp2[cur-val];
}
cout<<ans<<'\n';
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
212 KB |
Output is correct |
2 |
Correct |
2 ms |
212 KB |
Output is correct |
3 |
Correct |
2 ms |
328 KB |
Output is correct |
4 |
Correct |
2 ms |
212 KB |
Output is correct |
5 |
Correct |
2 ms |
324 KB |
Output is correct |
6 |
Correct |
2 ms |
324 KB |
Output is correct |
7 |
Correct |
2 ms |
340 KB |
Output is correct |
8 |
Correct |
2 ms |
340 KB |
Output is correct |
9 |
Correct |
2 ms |
212 KB |
Output is correct |
10 |
Correct |
2 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
212 KB |
Output is correct |
2 |
Correct |
2 ms |
212 KB |
Output is correct |
3 |
Correct |
2 ms |
328 KB |
Output is correct |
4 |
Correct |
2 ms |
212 KB |
Output is correct |
5 |
Correct |
2 ms |
324 KB |
Output is correct |
6 |
Correct |
2 ms |
324 KB |
Output is correct |
7 |
Correct |
2 ms |
340 KB |
Output is correct |
8 |
Correct |
2 ms |
340 KB |
Output is correct |
9 |
Correct |
2 ms |
212 KB |
Output is correct |
10 |
Correct |
2 ms |
212 KB |
Output is correct |
11 |
Correct |
1494 ms |
15056 KB |
Output is correct |
12 |
Correct |
1503 ms |
14720 KB |
Output is correct |
13 |
Correct |
1299 ms |
13952 KB |
Output is correct |
14 |
Correct |
1318 ms |
14084 KB |
Output is correct |
15 |
Correct |
1831 ms |
15044 KB |
Output is correct |
16 |
Correct |
1394 ms |
14176 KB |
Output is correct |
17 |
Correct |
1377 ms |
14200 KB |
Output is correct |
18 |
Correct |
1252 ms |
15964 KB |
Output is correct |
19 |
Correct |
1148 ms |
13052 KB |
Output is correct |
20 |
Correct |
1535 ms |
14652 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
212 KB |
Output is correct |
2 |
Correct |
2 ms |
212 KB |
Output is correct |
3 |
Correct |
2 ms |
328 KB |
Output is correct |
4 |
Correct |
2 ms |
212 KB |
Output is correct |
5 |
Correct |
2 ms |
324 KB |
Output is correct |
6 |
Correct |
2 ms |
324 KB |
Output is correct |
7 |
Correct |
2 ms |
340 KB |
Output is correct |
8 |
Correct |
2 ms |
340 KB |
Output is correct |
9 |
Correct |
2 ms |
212 KB |
Output is correct |
10 |
Correct |
2 ms |
212 KB |
Output is correct |
11 |
Correct |
1494 ms |
15056 KB |
Output is correct |
12 |
Correct |
1503 ms |
14720 KB |
Output is correct |
13 |
Correct |
1299 ms |
13952 KB |
Output is correct |
14 |
Correct |
1318 ms |
14084 KB |
Output is correct |
15 |
Correct |
1831 ms |
15044 KB |
Output is correct |
16 |
Correct |
1394 ms |
14176 KB |
Output is correct |
17 |
Correct |
1377 ms |
14200 KB |
Output is correct |
18 |
Correct |
1252 ms |
15964 KB |
Output is correct |
19 |
Correct |
1148 ms |
13052 KB |
Output is correct |
20 |
Correct |
1535 ms |
14652 KB |
Output is correct |
21 |
Execution timed out |
2017 ms |
18024 KB |
Time limit exceeded |
22 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
212 KB |
Output is correct |
2 |
Correct |
2 ms |
212 KB |
Output is correct |
3 |
Correct |
2 ms |
328 KB |
Output is correct |
4 |
Correct |
2 ms |
212 KB |
Output is correct |
5 |
Correct |
2 ms |
324 KB |
Output is correct |
6 |
Correct |
2 ms |
324 KB |
Output is correct |
7 |
Correct |
2 ms |
340 KB |
Output is correct |
8 |
Correct |
2 ms |
340 KB |
Output is correct |
9 |
Correct |
2 ms |
212 KB |
Output is correct |
10 |
Correct |
2 ms |
212 KB |
Output is correct |
11 |
Correct |
92 ms |
11928 KB |
Output is correct |
12 |
Correct |
91 ms |
11924 KB |
Output is correct |
13 |
Correct |
103 ms |
11856 KB |
Output is correct |
14 |
Correct |
132 ms |
11992 KB |
Output is correct |
15 |
Correct |
100 ms |
11956 KB |
Output is correct |
16 |
Correct |
125 ms |
11840 KB |
Output is correct |
17 |
Correct |
117 ms |
11836 KB |
Output is correct |
18 |
Correct |
86 ms |
12080 KB |
Output is correct |
19 |
Correct |
93 ms |
11760 KB |
Output is correct |
20 |
Correct |
93 ms |
11900 KB |
Output is correct |
21 |
Correct |
108 ms |
11968 KB |
Output is correct |
22 |
Correct |
127 ms |
11840 KB |
Output is correct |
23 |
Correct |
97 ms |
11756 KB |
Output is correct |
24 |
Correct |
124 ms |
11888 KB |
Output is correct |
25 |
Correct |
112 ms |
11884 KB |
Output is correct |
26 |
Correct |
84 ms |
11712 KB |
Output is correct |
27 |
Correct |
89 ms |
11880 KB |
Output is correct |
28 |
Correct |
83 ms |
11772 KB |
Output is correct |
29 |
Correct |
103 ms |
11844 KB |
Output is correct |
30 |
Correct |
120 ms |
11828 KB |
Output is correct |
31 |
Correct |
97 ms |
11808 KB |
Output is correct |
32 |
Correct |
124 ms |
11892 KB |
Output is correct |
33 |
Correct |
114 ms |
11932 KB |
Output is correct |
34 |
Correct |
84 ms |
11772 KB |
Output is correct |
35 |
Correct |
115 ms |
11860 KB |
Output is correct |
36 |
Correct |
107 ms |
11836 KB |
Output is correct |
37 |
Correct |
104 ms |
11860 KB |
Output is correct |
38 |
Correct |
118 ms |
12052 KB |
Output is correct |
39 |
Correct |
107 ms |
11880 KB |
Output is correct |
40 |
Correct |
105 ms |
11892 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
212 KB |
Output is correct |
2 |
Correct |
2 ms |
212 KB |
Output is correct |
3 |
Correct |
2 ms |
328 KB |
Output is correct |
4 |
Correct |
2 ms |
212 KB |
Output is correct |
5 |
Correct |
2 ms |
324 KB |
Output is correct |
6 |
Correct |
2 ms |
324 KB |
Output is correct |
7 |
Correct |
2 ms |
340 KB |
Output is correct |
8 |
Correct |
2 ms |
340 KB |
Output is correct |
9 |
Correct |
2 ms |
212 KB |
Output is correct |
10 |
Correct |
2 ms |
212 KB |
Output is correct |
11 |
Correct |
1494 ms |
15056 KB |
Output is correct |
12 |
Correct |
1503 ms |
14720 KB |
Output is correct |
13 |
Correct |
1299 ms |
13952 KB |
Output is correct |
14 |
Correct |
1318 ms |
14084 KB |
Output is correct |
15 |
Correct |
1831 ms |
15044 KB |
Output is correct |
16 |
Correct |
1394 ms |
14176 KB |
Output is correct |
17 |
Correct |
1377 ms |
14200 KB |
Output is correct |
18 |
Correct |
1252 ms |
15964 KB |
Output is correct |
19 |
Correct |
1148 ms |
13052 KB |
Output is correct |
20 |
Correct |
1535 ms |
14652 KB |
Output is correct |
21 |
Execution timed out |
2017 ms |
18024 KB |
Time limit exceeded |
22 |
Halted |
0 ms |
0 KB |
- |