#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
using vi = vector<int>;
#define sz(x) int(x.size())
int main()
{
int L, Q;
cin >> L >> Q;
vi A((1<<L));
for(int i = 0; i < (1<<L); i++)
{
char c;
cin >> c;
A[i] = c - '0';
}
vi lowersum = A;
vi uppersum = A;
for(int b = 0; b < L; b++)
{
for(int i = 0; i < (1<<L); i++)
{
if(i & (1<<b))
lowersum[i] += lowersum[i ^ (1<<b)];
else
uppersum[i] += uppersum[i ^ (1<<b)];
}
}
vi getbit((1<<L));
for(int i = 0; i < L; i++)
getbit[(1<<i)] = i;
for(int j = 0; j < Q; j++)
{
vi p0, p1, pq;
int onemask = 0;
for(int b = L-1; b >= 0; b--)
{
char c;
cin >> c;
if(c == '0')
p0.push_back(b);
else if(c == '1')
{
p1.push_back(b);
onemask += (1<<b);
}
else
pq.push_back(b);
}
int res = 0;
if(sz(pq) <= 10)
{
vi ssum((1 << sz(pq)), 0);
for(int m = 1; m < (1<<sz(pq)); m++)
ssum[m] = ssum[m - (m&-m)] + (1 << pq[getbit[m&-m]]);
for(int m = 0; m < (1<<sz(pq)); m++)
res += A[onemask | ssum[m]];
}
// cerr << test << ' ' << mask << '\n';
cout << res << '\n';
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
212 KB |
Output is correct |
2 |
Correct |
3 ms |
212 KB |
Output is correct |
3 |
Correct |
3 ms |
212 KB |
Output is correct |
4 |
Correct |
3 ms |
212 KB |
Output is correct |
5 |
Correct |
3 ms |
212 KB |
Output is correct |
6 |
Correct |
3 ms |
212 KB |
Output is correct |
7 |
Correct |
4 ms |
212 KB |
Output is correct |
8 |
Correct |
6 ms |
328 KB |
Output is correct |
9 |
Correct |
3 ms |
212 KB |
Output is correct |
10 |
Correct |
4 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
212 KB |
Output is correct |
2 |
Correct |
3 ms |
212 KB |
Output is correct |
3 |
Correct |
3 ms |
212 KB |
Output is correct |
4 |
Correct |
3 ms |
212 KB |
Output is correct |
5 |
Correct |
3 ms |
212 KB |
Output is correct |
6 |
Correct |
3 ms |
212 KB |
Output is correct |
7 |
Correct |
4 ms |
212 KB |
Output is correct |
8 |
Correct |
6 ms |
328 KB |
Output is correct |
9 |
Correct |
3 ms |
212 KB |
Output is correct |
10 |
Correct |
4 ms |
212 KB |
Output is correct |
11 |
Execution timed out |
2050 ms |
4632 KB |
Time limit exceeded |
12 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
212 KB |
Output is correct |
2 |
Correct |
3 ms |
212 KB |
Output is correct |
3 |
Correct |
3 ms |
212 KB |
Output is correct |
4 |
Correct |
3 ms |
212 KB |
Output is correct |
5 |
Correct |
3 ms |
212 KB |
Output is correct |
6 |
Correct |
3 ms |
212 KB |
Output is correct |
7 |
Correct |
4 ms |
212 KB |
Output is correct |
8 |
Correct |
6 ms |
328 KB |
Output is correct |
9 |
Correct |
3 ms |
212 KB |
Output is correct |
10 |
Correct |
4 ms |
212 KB |
Output is correct |
11 |
Execution timed out |
2050 ms |
4632 KB |
Time limit exceeded |
12 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
212 KB |
Output is correct |
2 |
Correct |
3 ms |
212 KB |
Output is correct |
3 |
Correct |
3 ms |
212 KB |
Output is correct |
4 |
Correct |
3 ms |
212 KB |
Output is correct |
5 |
Correct |
3 ms |
212 KB |
Output is correct |
6 |
Correct |
3 ms |
212 KB |
Output is correct |
7 |
Correct |
4 ms |
212 KB |
Output is correct |
8 |
Correct |
6 ms |
328 KB |
Output is correct |
9 |
Correct |
3 ms |
212 KB |
Output is correct |
10 |
Correct |
4 ms |
212 KB |
Output is correct |
11 |
Correct |
527 ms |
17660 KB |
Output is correct |
12 |
Incorrect |
303 ms |
18912 KB |
Output isn't correct |
13 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
212 KB |
Output is correct |
2 |
Correct |
3 ms |
212 KB |
Output is correct |
3 |
Correct |
3 ms |
212 KB |
Output is correct |
4 |
Correct |
3 ms |
212 KB |
Output is correct |
5 |
Correct |
3 ms |
212 KB |
Output is correct |
6 |
Correct |
3 ms |
212 KB |
Output is correct |
7 |
Correct |
4 ms |
212 KB |
Output is correct |
8 |
Correct |
6 ms |
328 KB |
Output is correct |
9 |
Correct |
3 ms |
212 KB |
Output is correct |
10 |
Correct |
4 ms |
212 KB |
Output is correct |
11 |
Execution timed out |
2050 ms |
4632 KB |
Time limit exceeded |
12 |
Halted |
0 ms |
0 KB |
- |