#include <bits/stdc++.h>
using namespace std;
#define sp " "
#define endl "\n";
#define fastio() cin.tie(0), ios_base::sync_with_stdio(0)
#define pb push_back
#define pii pair<int, int>
#define st first
#define nd second
#define N 9005
//#define int long long
const int modulo = 1e9 + 7;
int arr[N], dp[N][N];
int32_t main()
{
fastio();
int l, q;
cin>>l>>q;
for (int i = 0; i < (1<<l); i++)
{
char tmp;
cin>>tmp;
arr[i] = tmp - '0';
}
memset(dp, -1, sizeof(dp));
while(q--)
{
int s = 0, t = 0;
for (int i = l - 1; i >= 0; i--)
{
char tmp;
cin>>tmp;
if (tmp == '?') t |= (1<<i);
else if (tmp == '1') s |= (1<<i);
}
if (dp[s][t] != -1)
{
cout<<dp[s][t]<<endl;
continue;
}
int ans = 0;
for (int i = t; i != 0; i = (i - 1) & t)
ans += arr[s | i];
ans += arr[s];
dp[s][t] = ans;
cout<<ans<<endl;
}
cerr << "time taken : " << (float)clock() / CLOCKS_PER_SEC << " seconds\n";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
34 ms |
65536 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
34 ms |
65536 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
34 ms |
65536 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
34 ms |
65536 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
34 ms |
65536 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |