//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[2000010];
string s;
int pw[14];
int getans(int mask) {
if (ans[mask]!=-1) return ans[mask];
int nmask = mask;
int tmp = 1;
while (nmask%3!=2) nmask/=3,tmp*=3;
return ans[mask] = getans(mask-tmp) + getans(mask-2*tmp);
}
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;
memset(ans,-1,sizeof(ans));
rep(i,0,(1<<L)) {
int cur = (int)(s[i]-'0');
int val = 0;
rep(j,0,L) {
val += ((i>>j)&1)*pw[j];
}
ans[val] = cur;
}
rep(mask,0,pw[L]) getans(mask);
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 |
4 ms |
8148 KB |
Output is correct |
2 |
Correct |
4 ms |
8148 KB |
Output is correct |
3 |
Correct |
4 ms |
8148 KB |
Output is correct |
4 |
Correct |
4 ms |
8112 KB |
Output is correct |
5 |
Correct |
4 ms |
8148 KB |
Output is correct |
6 |
Correct |
5 ms |
8148 KB |
Output is correct |
7 |
Correct |
4 ms |
8148 KB |
Output is correct |
8 |
Correct |
3 ms |
8148 KB |
Output is correct |
9 |
Correct |
5 ms |
8148 KB |
Output is correct |
10 |
Correct |
4 ms |
8148 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
8148 KB |
Output is correct |
2 |
Correct |
4 ms |
8148 KB |
Output is correct |
3 |
Correct |
4 ms |
8148 KB |
Output is correct |
4 |
Correct |
4 ms |
8112 KB |
Output is correct |
5 |
Correct |
4 ms |
8148 KB |
Output is correct |
6 |
Correct |
5 ms |
8148 KB |
Output is correct |
7 |
Correct |
4 ms |
8148 KB |
Output is correct |
8 |
Correct |
3 ms |
8148 KB |
Output is correct |
9 |
Correct |
5 ms |
8148 KB |
Output is correct |
10 |
Correct |
4 ms |
8148 KB |
Output is correct |
11 |
Correct |
177 ms |
12032 KB |
Output is correct |
12 |
Correct |
195 ms |
11712 KB |
Output is correct |
13 |
Correct |
192 ms |
10968 KB |
Output is correct |
14 |
Correct |
194 ms |
11124 KB |
Output is correct |
15 |
Correct |
186 ms |
12128 KB |
Output is correct |
16 |
Correct |
199 ms |
11248 KB |
Output is correct |
17 |
Correct |
204 ms |
11284 KB |
Output is correct |
18 |
Correct |
146 ms |
13100 KB |
Output is correct |
19 |
Correct |
181 ms |
10028 KB |
Output is correct |
20 |
Correct |
187 ms |
11792 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
8148 KB |
Output is correct |
2 |
Correct |
4 ms |
8148 KB |
Output is correct |
3 |
Correct |
4 ms |
8148 KB |
Output is correct |
4 |
Correct |
4 ms |
8112 KB |
Output is correct |
5 |
Correct |
4 ms |
8148 KB |
Output is correct |
6 |
Correct |
5 ms |
8148 KB |
Output is correct |
7 |
Correct |
4 ms |
8148 KB |
Output is correct |
8 |
Correct |
3 ms |
8148 KB |
Output is correct |
9 |
Correct |
5 ms |
8148 KB |
Output is correct |
10 |
Correct |
4 ms |
8148 KB |
Output is correct |
11 |
Correct |
177 ms |
12032 KB |
Output is correct |
12 |
Correct |
195 ms |
11712 KB |
Output is correct |
13 |
Correct |
192 ms |
10968 KB |
Output is correct |
14 |
Correct |
194 ms |
11124 KB |
Output is correct |
15 |
Correct |
186 ms |
12128 KB |
Output is correct |
16 |
Correct |
199 ms |
11248 KB |
Output is correct |
17 |
Correct |
204 ms |
11284 KB |
Output is correct |
18 |
Correct |
146 ms |
13100 KB |
Output is correct |
19 |
Correct |
181 ms |
10028 KB |
Output is correct |
20 |
Correct |
187 ms |
11792 KB |
Output is correct |
21 |
Correct |
218 ms |
25716 KB |
Output is correct |
22 |
Correct |
263 ms |
25948 KB |
Output is correct |
23 |
Correct |
262 ms |
24972 KB |
Output is correct |
24 |
Correct |
265 ms |
24768 KB |
Output is correct |
25 |
Correct |
259 ms |
26876 KB |
Output is correct |
26 |
Correct |
335 ms |
25328 KB |
Output is correct |
27 |
Correct |
327 ms |
25232 KB |
Output is correct |
28 |
Correct |
206 ms |
27840 KB |
Output is correct |
29 |
Correct |
227 ms |
23752 KB |
Output is correct |
30 |
Correct |
264 ms |
26104 KB |
Output is correct |
31 |
Correct |
331 ms |
25980 KB |
Output is correct |
32 |
Correct |
280 ms |
25976 KB |
Output is correct |
33 |
Correct |
249 ms |
24776 KB |
Output is correct |
34 |
Correct |
264 ms |
24840 KB |
Output is correct |
35 |
Correct |
295 ms |
25388 KB |
Output is correct |
36 |
Correct |
161 ms |
23752 KB |
Output is correct |
37 |
Correct |
215 ms |
25912 KB |
Output is correct |
38 |
Correct |
220 ms |
23828 KB |
Output is correct |
39 |
Correct |
286 ms |
24976 KB |
Output is correct |
40 |
Correct |
280 ms |
24768 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
8148 KB |
Output is correct |
2 |
Correct |
4 ms |
8148 KB |
Output is correct |
3 |
Correct |
4 ms |
8148 KB |
Output is correct |
4 |
Correct |
4 ms |
8112 KB |
Output is correct |
5 |
Correct |
4 ms |
8148 KB |
Output is correct |
6 |
Correct |
5 ms |
8148 KB |
Output is correct |
7 |
Correct |
4 ms |
8148 KB |
Output is correct |
8 |
Correct |
3 ms |
8148 KB |
Output is correct |
9 |
Correct |
5 ms |
8148 KB |
Output is correct |
10 |
Correct |
4 ms |
8148 KB |
Output is correct |
11 |
Runtime error |
20 ms |
19668 KB |
Execution killed with signal 11 |
12 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
8148 KB |
Output is correct |
2 |
Correct |
4 ms |
8148 KB |
Output is correct |
3 |
Correct |
4 ms |
8148 KB |
Output is correct |
4 |
Correct |
4 ms |
8112 KB |
Output is correct |
5 |
Correct |
4 ms |
8148 KB |
Output is correct |
6 |
Correct |
5 ms |
8148 KB |
Output is correct |
7 |
Correct |
4 ms |
8148 KB |
Output is correct |
8 |
Correct |
3 ms |
8148 KB |
Output is correct |
9 |
Correct |
5 ms |
8148 KB |
Output is correct |
10 |
Correct |
4 ms |
8148 KB |
Output is correct |
11 |
Correct |
177 ms |
12032 KB |
Output is correct |
12 |
Correct |
195 ms |
11712 KB |
Output is correct |
13 |
Correct |
192 ms |
10968 KB |
Output is correct |
14 |
Correct |
194 ms |
11124 KB |
Output is correct |
15 |
Correct |
186 ms |
12128 KB |
Output is correct |
16 |
Correct |
199 ms |
11248 KB |
Output is correct |
17 |
Correct |
204 ms |
11284 KB |
Output is correct |
18 |
Correct |
146 ms |
13100 KB |
Output is correct |
19 |
Correct |
181 ms |
10028 KB |
Output is correct |
20 |
Correct |
187 ms |
11792 KB |
Output is correct |
21 |
Correct |
218 ms |
25716 KB |
Output is correct |
22 |
Correct |
263 ms |
25948 KB |
Output is correct |
23 |
Correct |
262 ms |
24972 KB |
Output is correct |
24 |
Correct |
265 ms |
24768 KB |
Output is correct |
25 |
Correct |
259 ms |
26876 KB |
Output is correct |
26 |
Correct |
335 ms |
25328 KB |
Output is correct |
27 |
Correct |
327 ms |
25232 KB |
Output is correct |
28 |
Correct |
206 ms |
27840 KB |
Output is correct |
29 |
Correct |
227 ms |
23752 KB |
Output is correct |
30 |
Correct |
264 ms |
26104 KB |
Output is correct |
31 |
Correct |
331 ms |
25980 KB |
Output is correct |
32 |
Correct |
280 ms |
25976 KB |
Output is correct |
33 |
Correct |
249 ms |
24776 KB |
Output is correct |
34 |
Correct |
264 ms |
24840 KB |
Output is correct |
35 |
Correct |
295 ms |
25388 KB |
Output is correct |
36 |
Correct |
161 ms |
23752 KB |
Output is correct |
37 |
Correct |
215 ms |
25912 KB |
Output is correct |
38 |
Correct |
220 ms |
23828 KB |
Output is correct |
39 |
Correct |
286 ms |
24976 KB |
Output is correct |
40 |
Correct |
280 ms |
24768 KB |
Output is correct |
41 |
Runtime error |
20 ms |
19668 KB |
Execution killed with signal 11 |
42 |
Halted |
0 ms |
0 KB |
- |