#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 20000005
//#define int long long
const int modulo = 1e9 + 7;
int arr[N], ans[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';
}
vector<pair<pii, int>> que;
for (int j = 1; j <= q; j++)
{
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);
}
que.pb({{s, t}, j});
}
sort(que.begin(), que.end());
for (int i = 0; i < q; i++)
{
int s = que[i].st.st, t = que[i].st.nd, ind = que[i].nd;
if (i > 0)
{
if (s == que[i - 1].st.st && t == que[i - 1].st.nd)
{
ans[ind] = ans[que[i - 1].nd];
continue;
}
}
for (int j = t; j != 0; j = (j - 1) & t)
ans[ind] += arr[s | j];
ans[ind] += arr[s];
}
for (int i = 1; i <= q; i++)
cout<<ans[i]<<endl;
cerr << "time taken : " << (float)clock() / CLOCKS_PER_SEC << " seconds\n";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
2 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
2 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
2 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
2 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
414 ms |
20408 KB |
Output is correct |
12 |
Correct |
420 ms |
20016 KB |
Output is correct |
13 |
Correct |
391 ms |
19252 KB |
Output is correct |
14 |
Correct |
413 ms |
19376 KB |
Output is correct |
15 |
Correct |
418 ms |
20356 KB |
Output is correct |
16 |
Correct |
389 ms |
19480 KB |
Output is correct |
17 |
Correct |
392 ms |
19568 KB |
Output is correct |
18 |
Correct |
270 ms |
21324 KB |
Output is correct |
19 |
Correct |
322 ms |
18332 KB |
Output is correct |
20 |
Correct |
430 ms |
20164 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
2 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
2 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
414 ms |
20408 KB |
Output is correct |
12 |
Correct |
420 ms |
20016 KB |
Output is correct |
13 |
Correct |
391 ms |
19252 KB |
Output is correct |
14 |
Correct |
413 ms |
19376 KB |
Output is correct |
15 |
Correct |
418 ms |
20356 KB |
Output is correct |
16 |
Correct |
389 ms |
19480 KB |
Output is correct |
17 |
Correct |
392 ms |
19568 KB |
Output is correct |
18 |
Correct |
270 ms |
21324 KB |
Output is correct |
19 |
Correct |
322 ms |
18332 KB |
Output is correct |
20 |
Correct |
430 ms |
20164 KB |
Output is correct |
21 |
Correct |
460 ms |
20664 KB |
Output is correct |
22 |
Correct |
482 ms |
20508 KB |
Output is correct |
23 |
Correct |
431 ms |
19612 KB |
Output is correct |
24 |
Correct |
451 ms |
19360 KB |
Output is correct |
25 |
Correct |
510 ms |
21468 KB |
Output is correct |
26 |
Correct |
467 ms |
20064 KB |
Output is correct |
27 |
Correct |
472 ms |
19844 KB |
Output is correct |
28 |
Correct |
282 ms |
22896 KB |
Output is correct |
29 |
Correct |
344 ms |
18536 KB |
Output is correct |
30 |
Correct |
464 ms |
20672 KB |
Output is correct |
31 |
Correct |
494 ms |
20560 KB |
Output is correct |
32 |
Correct |
471 ms |
20464 KB |
Output is correct |
33 |
Correct |
407 ms |
19400 KB |
Output is correct |
34 |
Correct |
434 ms |
19556 KB |
Output is correct |
35 |
Correct |
508 ms |
19976 KB |
Output is correct |
36 |
Correct |
284 ms |
18428 KB |
Output is correct |
37 |
Correct |
460 ms |
20512 KB |
Output is correct |
38 |
Correct |
343 ms |
18600 KB |
Output is correct |
39 |
Correct |
459 ms |
19852 KB |
Output is correct |
40 |
Correct |
432 ms |
19492 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
2 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
2 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
86 ms |
7544 KB |
Output is correct |
12 |
Correct |
192 ms |
7660 KB |
Output is correct |
13 |
Correct |
48 ms |
7492 KB |
Output is correct |
14 |
Correct |
56 ms |
7596 KB |
Output is correct |
15 |
Correct |
417 ms |
7656 KB |
Output is correct |
16 |
Correct |
55 ms |
7536 KB |
Output is correct |
17 |
Correct |
57 ms |
7528 KB |
Output is correct |
18 |
Correct |
36 ms |
7752 KB |
Output is correct |
19 |
Correct |
40 ms |
7492 KB |
Output is correct |
20 |
Correct |
188 ms |
7660 KB |
Output is correct |
21 |
Correct |
100 ms |
7564 KB |
Output is correct |
22 |
Correct |
50 ms |
7512 KB |
Output is correct |
23 |
Correct |
41 ms |
7492 KB |
Output is correct |
24 |
Correct |
49 ms |
7580 KB |
Output is correct |
25 |
Correct |
64 ms |
7508 KB |
Output is correct |
26 |
Correct |
35 ms |
7400 KB |
Output is correct |
27 |
Correct |
90 ms |
7584 KB |
Output is correct |
28 |
Correct |
44 ms |
7412 KB |
Output is correct |
29 |
Correct |
56 ms |
7536 KB |
Output is correct |
30 |
Correct |
51 ms |
7604 KB |
Output is correct |
31 |
Correct |
43 ms |
7560 KB |
Output is correct |
32 |
Correct |
62 ms |
7580 KB |
Output is correct |
33 |
Correct |
60 ms |
7664 KB |
Output is correct |
34 |
Correct |
35 ms |
7512 KB |
Output is correct |
35 |
Correct |
92 ms |
7500 KB |
Output is correct |
36 |
Correct |
85 ms |
7540 KB |
Output is correct |
37 |
Correct |
81 ms |
7620 KB |
Output is correct |
38 |
Correct |
86 ms |
7636 KB |
Output is correct |
39 |
Correct |
89 ms |
7508 KB |
Output is correct |
40 |
Correct |
97 ms |
7528 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
2 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
2 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
414 ms |
20408 KB |
Output is correct |
12 |
Correct |
420 ms |
20016 KB |
Output is correct |
13 |
Correct |
391 ms |
19252 KB |
Output is correct |
14 |
Correct |
413 ms |
19376 KB |
Output is correct |
15 |
Correct |
418 ms |
20356 KB |
Output is correct |
16 |
Correct |
389 ms |
19480 KB |
Output is correct |
17 |
Correct |
392 ms |
19568 KB |
Output is correct |
18 |
Correct |
270 ms |
21324 KB |
Output is correct |
19 |
Correct |
322 ms |
18332 KB |
Output is correct |
20 |
Correct |
430 ms |
20164 KB |
Output is correct |
21 |
Correct |
460 ms |
20664 KB |
Output is correct |
22 |
Correct |
482 ms |
20508 KB |
Output is correct |
23 |
Correct |
431 ms |
19612 KB |
Output is correct |
24 |
Correct |
451 ms |
19360 KB |
Output is correct |
25 |
Correct |
510 ms |
21468 KB |
Output is correct |
26 |
Correct |
467 ms |
20064 KB |
Output is correct |
27 |
Correct |
472 ms |
19844 KB |
Output is correct |
28 |
Correct |
282 ms |
22896 KB |
Output is correct |
29 |
Correct |
344 ms |
18536 KB |
Output is correct |
30 |
Correct |
464 ms |
20672 KB |
Output is correct |
31 |
Correct |
494 ms |
20560 KB |
Output is correct |
32 |
Correct |
471 ms |
20464 KB |
Output is correct |
33 |
Correct |
407 ms |
19400 KB |
Output is correct |
34 |
Correct |
434 ms |
19556 KB |
Output is correct |
35 |
Correct |
508 ms |
19976 KB |
Output is correct |
36 |
Correct |
284 ms |
18428 KB |
Output is correct |
37 |
Correct |
460 ms |
20512 KB |
Output is correct |
38 |
Correct |
343 ms |
18600 KB |
Output is correct |
39 |
Correct |
459 ms |
19852 KB |
Output is correct |
40 |
Correct |
432 ms |
19492 KB |
Output is correct |
41 |
Correct |
86 ms |
7544 KB |
Output is correct |
42 |
Correct |
192 ms |
7660 KB |
Output is correct |
43 |
Correct |
48 ms |
7492 KB |
Output is correct |
44 |
Correct |
56 ms |
7596 KB |
Output is correct |
45 |
Correct |
417 ms |
7656 KB |
Output is correct |
46 |
Correct |
55 ms |
7536 KB |
Output is correct |
47 |
Correct |
57 ms |
7528 KB |
Output is correct |
48 |
Correct |
36 ms |
7752 KB |
Output is correct |
49 |
Correct |
40 ms |
7492 KB |
Output is correct |
50 |
Correct |
188 ms |
7660 KB |
Output is correct |
51 |
Correct |
100 ms |
7564 KB |
Output is correct |
52 |
Correct |
50 ms |
7512 KB |
Output is correct |
53 |
Correct |
41 ms |
7492 KB |
Output is correct |
54 |
Correct |
49 ms |
7580 KB |
Output is correct |
55 |
Correct |
64 ms |
7508 KB |
Output is correct |
56 |
Correct |
35 ms |
7400 KB |
Output is correct |
57 |
Correct |
90 ms |
7584 KB |
Output is correct |
58 |
Correct |
44 ms |
7412 KB |
Output is correct |
59 |
Correct |
56 ms |
7536 KB |
Output is correct |
60 |
Correct |
51 ms |
7604 KB |
Output is correct |
61 |
Correct |
43 ms |
7560 KB |
Output is correct |
62 |
Correct |
62 ms |
7580 KB |
Output is correct |
63 |
Correct |
60 ms |
7664 KB |
Output is correct |
64 |
Correct |
35 ms |
7512 KB |
Output is correct |
65 |
Correct |
92 ms |
7500 KB |
Output is correct |
66 |
Correct |
85 ms |
7540 KB |
Output is correct |
67 |
Correct |
81 ms |
7620 KB |
Output is correct |
68 |
Correct |
86 ms |
7636 KB |
Output is correct |
69 |
Correct |
89 ms |
7508 KB |
Output is correct |
70 |
Correct |
97 ms |
7528 KB |
Output is correct |
71 |
Correct |
780 ms |
46744 KB |
Output is correct |
72 |
Execution timed out |
2056 ms |
41748 KB |
Time limit exceeded |
73 |
Halted |
0 ms |
0 KB |
- |