#include <bits/stdc++.h>
using namespace std;
#define forw(i,a,b) for(ll i=a;i<=b;i++)
#define forb(i,a,b) for(int i=a;i>=b;i--)
#define pu push
#define pb push_back
#define fi first
#define se second
#define all(a) a.begin(),a.end()
typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ll,pair<ll,ll> > plll;
const ll maxN=(1<<13)+5;
const ll oo=1e18;
unordered_map<ll,ll> save[maxN];
ll n,q;
void solve()
{
cin>>n>>q;
forw(mask1,0,(1<<n)-1)
{
char c; cin>>c;
forw(mask2,0,(1<<n)-1)
{
ll tmp=mask1&mask2;
ll new_mask=mask1-tmp;
save[mask2][new_mask]+=(c-'0');
//if (mask2==6 && new_mask==0) cout<<mask1<<" "<<(c-'0')<<endl;
}
}
while (q--)
{
string s; cin>>s; reverse(all(s));
ll mask1=0;
ll mask2=0;
forw(i,0,n-1)
if (s[i]=='?') mask2+=(1LL<<i);
else
mask1+=(1LL<<i)*(s[i]=='1');
if (save[mask2].find(mask1)!=save[mask2].end())
cout<<save[mask2][mask1]<<"\n";
else
cout<<0<<"\n";
}
return;
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
//freopen("c.inp","r",stdin);
//freopen("c.out","w",stdout);
solve();
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
33 ms |
3412 KB |
Output is correct |
2 |
Correct |
33 ms |
3396 KB |
Output is correct |
3 |
Correct |
34 ms |
3328 KB |
Output is correct |
4 |
Correct |
35 ms |
3312 KB |
Output is correct |
5 |
Correct |
35 ms |
3412 KB |
Output is correct |
6 |
Correct |
34 ms |
3380 KB |
Output is correct |
7 |
Correct |
33 ms |
3312 KB |
Output is correct |
8 |
Correct |
32 ms |
3328 KB |
Output is correct |
9 |
Correct |
32 ms |
3348 KB |
Output is correct |
10 |
Correct |
33 ms |
3404 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
33 ms |
3412 KB |
Output is correct |
2 |
Correct |
33 ms |
3396 KB |
Output is correct |
3 |
Correct |
34 ms |
3328 KB |
Output is correct |
4 |
Correct |
35 ms |
3312 KB |
Output is correct |
5 |
Correct |
35 ms |
3412 KB |
Output is correct |
6 |
Correct |
34 ms |
3380 KB |
Output is correct |
7 |
Correct |
33 ms |
3312 KB |
Output is correct |
8 |
Correct |
32 ms |
3328 KB |
Output is correct |
9 |
Correct |
32 ms |
3348 KB |
Output is correct |
10 |
Correct |
33 ms |
3404 KB |
Output is correct |
11 |
Correct |
216 ms |
7392 KB |
Output is correct |
12 |
Correct |
239 ms |
7116 KB |
Output is correct |
13 |
Correct |
267 ms |
6356 KB |
Output is correct |
14 |
Correct |
243 ms |
6396 KB |
Output is correct |
15 |
Correct |
225 ms |
7360 KB |
Output is correct |
16 |
Correct |
254 ms |
6604 KB |
Output is correct |
17 |
Correct |
253 ms |
6540 KB |
Output is correct |
18 |
Correct |
216 ms |
8588 KB |
Output is correct |
19 |
Correct |
181 ms |
5324 KB |
Output is correct |
20 |
Correct |
260 ms |
7156 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
33 ms |
3412 KB |
Output is correct |
2 |
Correct |
33 ms |
3396 KB |
Output is correct |
3 |
Correct |
34 ms |
3328 KB |
Output is correct |
4 |
Correct |
35 ms |
3312 KB |
Output is correct |
5 |
Correct |
35 ms |
3412 KB |
Output is correct |
6 |
Correct |
34 ms |
3380 KB |
Output is correct |
7 |
Correct |
33 ms |
3312 KB |
Output is correct |
8 |
Correct |
32 ms |
3328 KB |
Output is correct |
9 |
Correct |
32 ms |
3348 KB |
Output is correct |
10 |
Correct |
33 ms |
3404 KB |
Output is correct |
11 |
Correct |
216 ms |
7392 KB |
Output is correct |
12 |
Correct |
239 ms |
7116 KB |
Output is correct |
13 |
Correct |
267 ms |
6356 KB |
Output is correct |
14 |
Correct |
243 ms |
6396 KB |
Output is correct |
15 |
Correct |
225 ms |
7360 KB |
Output is correct |
16 |
Correct |
254 ms |
6604 KB |
Output is correct |
17 |
Correct |
253 ms |
6540 KB |
Output is correct |
18 |
Correct |
216 ms |
8588 KB |
Output is correct |
19 |
Correct |
181 ms |
5324 KB |
Output is correct |
20 |
Correct |
260 ms |
7156 KB |
Output is correct |
21 |
Execution timed out |
2093 ms |
42604 KB |
Time limit exceeded |
22 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
33 ms |
3412 KB |
Output is correct |
2 |
Correct |
33 ms |
3396 KB |
Output is correct |
3 |
Correct |
34 ms |
3328 KB |
Output is correct |
4 |
Correct |
35 ms |
3312 KB |
Output is correct |
5 |
Correct |
35 ms |
3412 KB |
Output is correct |
6 |
Correct |
34 ms |
3380 KB |
Output is correct |
7 |
Correct |
33 ms |
3312 KB |
Output is correct |
8 |
Correct |
32 ms |
3328 KB |
Output is correct |
9 |
Correct |
32 ms |
3348 KB |
Output is correct |
10 |
Correct |
33 ms |
3404 KB |
Output is correct |
11 |
Runtime error |
4 ms |
3612 KB |
Execution killed with signal 11 |
12 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
33 ms |
3412 KB |
Output is correct |
2 |
Correct |
33 ms |
3396 KB |
Output is correct |
3 |
Correct |
34 ms |
3328 KB |
Output is correct |
4 |
Correct |
35 ms |
3312 KB |
Output is correct |
5 |
Correct |
35 ms |
3412 KB |
Output is correct |
6 |
Correct |
34 ms |
3380 KB |
Output is correct |
7 |
Correct |
33 ms |
3312 KB |
Output is correct |
8 |
Correct |
32 ms |
3328 KB |
Output is correct |
9 |
Correct |
32 ms |
3348 KB |
Output is correct |
10 |
Correct |
33 ms |
3404 KB |
Output is correct |
11 |
Correct |
216 ms |
7392 KB |
Output is correct |
12 |
Correct |
239 ms |
7116 KB |
Output is correct |
13 |
Correct |
267 ms |
6356 KB |
Output is correct |
14 |
Correct |
243 ms |
6396 KB |
Output is correct |
15 |
Correct |
225 ms |
7360 KB |
Output is correct |
16 |
Correct |
254 ms |
6604 KB |
Output is correct |
17 |
Correct |
253 ms |
6540 KB |
Output is correct |
18 |
Correct |
216 ms |
8588 KB |
Output is correct |
19 |
Correct |
181 ms |
5324 KB |
Output is correct |
20 |
Correct |
260 ms |
7156 KB |
Output is correct |
21 |
Execution timed out |
2093 ms |
42604 KB |
Time limit exceeded |
22 |
Halted |
0 ms |
0 KB |
- |