//by szh
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pii pair<int,int>
#define pll pair<long long,long long>
#define pb push_back
#define debug(x) cerr<<#x<<"="<<x<<endl
#define pq priority_queue
#define inf 0x3f
#define rep(i,a,b) for (int i=a;i<(b);i++)
#define MP make_pair
#define SZ(x) (int(x.size()))
#define ll long long
#define mod 1000000007
#define ALL(x) x.begin(),x.end()
void inc(int &a,int b) {a=(a+b)%mod;}
void dec(int &a,int b) {a=(a-b+mod)%mod;}
int lowbit(int x) {return x&(-x);}
ll p0w(ll base,ll p) {ll ret=1;while(p>0){if (p%2ll==1ll) ret=ret*base%mod;base=base*base%mod;p/=2ll;}return ret;}
int L,Q;
int ans[200010];
string s;
int pw[14];
int main() {
// freopen("input.txt","r",stdin);
std::ios::sync_with_stdio(false);cin.tie(0);
pw[0]=1;
rep(i,1,14) pw[i] = pw[i-1]*3;
cin>>L>>Q;
cin>>s;
rep(i,0,(1<<L)) {
int cur = (int)(s[i]-'0');
rep(mask,0,(1<<L)) {
int val = 0;
rep(j,0,L) {
if ((mask>>j)&1) val+=2*pw[j];
else val += ((i>>j)&1)*pw[j];
}
ans[val] += cur;
}
}
while (Q--) {
string ss;cin>>ss;
int mask = 0;
rep(i,0,L) {
if (ss[L-1-i]=='1') mask+=pw[i];
else if (ss[L-1-i]=='?') mask+=pw[i]*2;
}
cout<<ans[mask]<<"\n";
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
468 KB |
Output is correct |
2 |
Correct |
17 ms |
504 KB |
Output is correct |
3 |
Correct |
18 ms |
548 KB |
Output is correct |
4 |
Correct |
18 ms |
572 KB |
Output is correct |
5 |
Correct |
18 ms |
492 KB |
Output is correct |
6 |
Correct |
17 ms |
492 KB |
Output is correct |
7 |
Correct |
18 ms |
472 KB |
Output is correct |
8 |
Correct |
17 ms |
468 KB |
Output is correct |
9 |
Correct |
17 ms |
488 KB |
Output is correct |
10 |
Correct |
17 ms |
468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
468 KB |
Output is correct |
2 |
Correct |
17 ms |
504 KB |
Output is correct |
3 |
Correct |
18 ms |
548 KB |
Output is correct |
4 |
Correct |
18 ms |
572 KB |
Output is correct |
5 |
Correct |
18 ms |
492 KB |
Output is correct |
6 |
Correct |
17 ms |
492 KB |
Output is correct |
7 |
Correct |
18 ms |
472 KB |
Output is correct |
8 |
Correct |
17 ms |
468 KB |
Output is correct |
9 |
Correct |
17 ms |
488 KB |
Output is correct |
10 |
Correct |
17 ms |
468 KB |
Output is correct |
11 |
Correct |
206 ms |
15332 KB |
Output is correct |
12 |
Correct |
210 ms |
14932 KB |
Output is correct |
13 |
Correct |
209 ms |
14156 KB |
Output is correct |
14 |
Correct |
219 ms |
14272 KB |
Output is correct |
15 |
Correct |
213 ms |
15308 KB |
Output is correct |
16 |
Correct |
221 ms |
14412 KB |
Output is correct |
17 |
Correct |
229 ms |
14508 KB |
Output is correct |
18 |
Correct |
166 ms |
16304 KB |
Output is correct |
19 |
Correct |
195 ms |
13316 KB |
Output is correct |
20 |
Correct |
209 ms |
14888 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
468 KB |
Output is correct |
2 |
Correct |
17 ms |
504 KB |
Output is correct |
3 |
Correct |
18 ms |
548 KB |
Output is correct |
4 |
Correct |
18 ms |
572 KB |
Output is correct |
5 |
Correct |
18 ms |
492 KB |
Output is correct |
6 |
Correct |
17 ms |
492 KB |
Output is correct |
7 |
Correct |
18 ms |
472 KB |
Output is correct |
8 |
Correct |
17 ms |
468 KB |
Output is correct |
9 |
Correct |
17 ms |
488 KB |
Output is correct |
10 |
Correct |
17 ms |
468 KB |
Output is correct |
11 |
Correct |
206 ms |
15332 KB |
Output is correct |
12 |
Correct |
210 ms |
14932 KB |
Output is correct |
13 |
Correct |
209 ms |
14156 KB |
Output is correct |
14 |
Correct |
219 ms |
14272 KB |
Output is correct |
15 |
Correct |
213 ms |
15308 KB |
Output is correct |
16 |
Correct |
221 ms |
14412 KB |
Output is correct |
17 |
Correct |
229 ms |
14508 KB |
Output is correct |
18 |
Correct |
166 ms |
16304 KB |
Output is correct |
19 |
Correct |
195 ms |
13316 KB |
Output is correct |
20 |
Correct |
209 ms |
14888 KB |
Output is correct |
21 |
Runtime error |
1 ms |
980 KB |
Execution killed with signal 11 |
22 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
468 KB |
Output is correct |
2 |
Correct |
17 ms |
504 KB |
Output is correct |
3 |
Correct |
18 ms |
548 KB |
Output is correct |
4 |
Correct |
18 ms |
572 KB |
Output is correct |
5 |
Correct |
18 ms |
492 KB |
Output is correct |
6 |
Correct |
17 ms |
492 KB |
Output is correct |
7 |
Correct |
18 ms |
472 KB |
Output is correct |
8 |
Correct |
17 ms |
468 KB |
Output is correct |
9 |
Correct |
17 ms |
488 KB |
Output is correct |
10 |
Correct |
17 ms |
468 KB |
Output is correct |
11 |
Runtime error |
5 ms |
4404 KB |
Execution killed with signal 11 |
12 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
468 KB |
Output is correct |
2 |
Correct |
17 ms |
504 KB |
Output is correct |
3 |
Correct |
18 ms |
548 KB |
Output is correct |
4 |
Correct |
18 ms |
572 KB |
Output is correct |
5 |
Correct |
18 ms |
492 KB |
Output is correct |
6 |
Correct |
17 ms |
492 KB |
Output is correct |
7 |
Correct |
18 ms |
472 KB |
Output is correct |
8 |
Correct |
17 ms |
468 KB |
Output is correct |
9 |
Correct |
17 ms |
488 KB |
Output is correct |
10 |
Correct |
17 ms |
468 KB |
Output is correct |
11 |
Correct |
206 ms |
15332 KB |
Output is correct |
12 |
Correct |
210 ms |
14932 KB |
Output is correct |
13 |
Correct |
209 ms |
14156 KB |
Output is correct |
14 |
Correct |
219 ms |
14272 KB |
Output is correct |
15 |
Correct |
213 ms |
15308 KB |
Output is correct |
16 |
Correct |
221 ms |
14412 KB |
Output is correct |
17 |
Correct |
229 ms |
14508 KB |
Output is correct |
18 |
Correct |
166 ms |
16304 KB |
Output is correct |
19 |
Correct |
195 ms |
13316 KB |
Output is correct |
20 |
Correct |
209 ms |
14888 KB |
Output is correct |
21 |
Runtime error |
1 ms |
980 KB |
Execution killed with signal 11 |
22 |
Halted |
0 ms |
0 KB |
- |