/*
-------------- | /
| | /
| | /
| * |/ | | ------ *
| | | | / \
| | |\ | | | |\ |
\ | | | \ | | | | \ |
\ | | | \ | | \ / \ |
V | | \ \__/| ----- \ |
*/
#include <bits/stdc++.h>
using namespace std;
#define debug(x) cerr << "\e[1;31m" << #x << " = " << (x) << "\e[0m\n"
#define print(x) emilia_mata_tenshi(#x, begin(x), end(x))
template<typename T> void emilia_mata_tenshi(const char *s, T l, T r) {
cerr << "\e[1;33m" << s << " = [";
while(l != r) {
cerr << *l;
cerr << (++l == r ? ']' : ',');
}
cerr << "\e[0m\n";
}
#define EmiliaMyWife ios::sync_with_stdio(0); cin.tie(NULL);
using ll = int64_t;
using ull = uint64_t;
using ld = long double;
using uint = uint32_t;
const double EPS = 1e-8;
const int INF = 0x3F3F3F3F;
const ll LINF = 4611686018427387903;
const int MOD = 1e9+7;
static int Lamy_is_cute = []() {
EmiliaMyWife
return 48763;
}();
/*--------------------------------------------------------------------------------------*/
signed main() {
int l, q;
cin >> l >> q;
vector<int> arr(1 << l), dp(1 << l);
{
string s;
cin >> s;
for(int i = 0; i < (1 << l); i++)
arr[i] = dp[i] = s[i] - '0';
}
for(int i = 0; i < l; i++)
for(int j = 0; j < (1 << l); j++)
if(j >> i & 1)
dp[j] += dp[j ^ (1 << i)];
function<int(const string&, int, int)> dfs = [&](const string &s, int n, int cur) {
if(n == l)
return arr[cur];
if(s[n] == '?')
return dfs(s, n + 1, cur) + dfs(s, n + 1, cur | (1 << n));
if(s[n] == '1')
return dfs(s, n + 1, cur | (1 << n));
return dfs(s, n + 1, cur);
};
function<int(const string &s, int, int, int)> dfs2 = [&](const string &s, int n, int cur, int cnt) {
if(n == l)
return dp[cur] * (cnt % 2 ? -1 : 1);
if(s[n] == '?')
return dfs2(s, n + 1, cur | (1 << n), cnt);
if(s[n] == '0')
return dfs2(s, n + 1, cur, cnt);
return dfs2(s, n + 1, cur | (1 << n), cnt) + dfs2(s, n + 1, cur, cnt + 1);
};
while(q--) {
string s;
cin >> s;
reverse(s.begin(), s.end());
int cnt = 0;
for(char c : s)
cnt += c == '?';
if(cnt * 2 <= l)
cout << dfs(s, 0, 0) << '\n';
else
cout << dfs2(s, 0, 0, 0) << '\n';
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
312 KB |
Output is correct |
2 |
Correct |
1 ms |
312 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
2 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
316 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
312 KB |
Output is correct |
2 |
Correct |
1 ms |
312 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
2 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
316 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
937 ms |
15020 KB |
Output is correct |
12 |
Correct |
552 ms |
14728 KB |
Output is correct |
13 |
Correct |
500 ms |
13988 KB |
Output is correct |
14 |
Correct |
528 ms |
14024 KB |
Output is correct |
15 |
Correct |
479 ms |
15004 KB |
Output is correct |
16 |
Correct |
636 ms |
14324 KB |
Output is correct |
17 |
Correct |
597 ms |
14104 KB |
Output is correct |
18 |
Correct |
306 ms |
15944 KB |
Output is correct |
19 |
Correct |
298 ms |
12996 KB |
Output is correct |
20 |
Correct |
726 ms |
14704 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
312 KB |
Output is correct |
2 |
Correct |
1 ms |
312 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
2 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
316 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
937 ms |
15020 KB |
Output is correct |
12 |
Correct |
552 ms |
14728 KB |
Output is correct |
13 |
Correct |
500 ms |
13988 KB |
Output is correct |
14 |
Correct |
528 ms |
14024 KB |
Output is correct |
15 |
Correct |
479 ms |
15004 KB |
Output is correct |
16 |
Correct |
636 ms |
14324 KB |
Output is correct |
17 |
Correct |
597 ms |
14104 KB |
Output is correct |
18 |
Correct |
306 ms |
15944 KB |
Output is correct |
19 |
Correct |
298 ms |
12996 KB |
Output is correct |
20 |
Correct |
726 ms |
14704 KB |
Output is correct |
21 |
Correct |
2000 ms |
17956 KB |
Output is correct |
22 |
Correct |
773 ms |
18240 KB |
Output is correct |
23 |
Correct |
841 ms |
17208 KB |
Output is correct |
24 |
Correct |
876 ms |
17172 KB |
Output is correct |
25 |
Correct |
613 ms |
19080 KB |
Output is correct |
26 |
Correct |
1028 ms |
17568 KB |
Output is correct |
27 |
Correct |
974 ms |
17516 KB |
Output is correct |
28 |
Correct |
254 ms |
20076 KB |
Output is correct |
29 |
Correct |
300 ms |
15988 KB |
Output is correct |
30 |
Correct |
1336 ms |
18208 KB |
Output is correct |
31 |
Correct |
1851 ms |
17996 KB |
Output is correct |
32 |
Correct |
1249 ms |
18080 KB |
Output is correct |
33 |
Correct |
549 ms |
17068 KB |
Output is correct |
34 |
Correct |
875 ms |
17076 KB |
Output is correct |
35 |
Correct |
996 ms |
17640 KB |
Output is correct |
36 |
Correct |
238 ms |
16012 KB |
Output is correct |
37 |
Correct |
1679 ms |
18152 KB |
Output is correct |
38 |
Correct |
320 ms |
16056 KB |
Output is correct |
39 |
Correct |
820 ms |
17316 KB |
Output is correct |
40 |
Correct |
876 ms |
16984 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
312 KB |
Output is correct |
2 |
Correct |
1 ms |
312 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
2 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
316 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1162 ms |
11944 KB |
Output is correct |
12 |
Correct |
407 ms |
11864 KB |
Output is correct |
13 |
Correct |
166 ms |
11940 KB |
Output is correct |
14 |
Correct |
251 ms |
11880 KB |
Output is correct |
15 |
Correct |
94 ms |
11872 KB |
Output is correct |
16 |
Correct |
344 ms |
11932 KB |
Output is correct |
17 |
Correct |
328 ms |
11952 KB |
Output is correct |
18 |
Correct |
44 ms |
11928 KB |
Output is correct |
19 |
Correct |
47 ms |
11872 KB |
Output is correct |
20 |
Correct |
608 ms |
11908 KB |
Output is correct |
21 |
Correct |
1148 ms |
11872 KB |
Output is correct |
22 |
Correct |
252 ms |
11872 KB |
Output is correct |
23 |
Correct |
85 ms |
11840 KB |
Output is correct |
24 |
Correct |
190 ms |
11996 KB |
Output is correct |
25 |
Correct |
299 ms |
11872 KB |
Output is correct |
26 |
Correct |
41 ms |
11872 KB |
Output is correct |
27 |
Correct |
1120 ms |
11864 KB |
Output is correct |
28 |
Correct |
50 ms |
11872 KB |
Output is correct |
29 |
Correct |
145 ms |
11932 KB |
Output is correct |
30 |
Correct |
180 ms |
11944 KB |
Output is correct |
31 |
Correct |
84 ms |
11948 KB |
Output is correct |
32 |
Correct |
350 ms |
11880 KB |
Output is correct |
33 |
Correct |
312 ms |
11836 KB |
Output is correct |
34 |
Correct |
41 ms |
11872 KB |
Output is correct |
35 |
Correct |
349 ms |
11852 KB |
Output is correct |
36 |
Correct |
332 ms |
11956 KB |
Output is correct |
37 |
Correct |
344 ms |
11948 KB |
Output is correct |
38 |
Correct |
332 ms |
12000 KB |
Output is correct |
39 |
Correct |
345 ms |
11872 KB |
Output is correct |
40 |
Correct |
326 ms |
11872 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
312 KB |
Output is correct |
2 |
Correct |
1 ms |
312 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
2 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
316 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
937 ms |
15020 KB |
Output is correct |
12 |
Correct |
552 ms |
14728 KB |
Output is correct |
13 |
Correct |
500 ms |
13988 KB |
Output is correct |
14 |
Correct |
528 ms |
14024 KB |
Output is correct |
15 |
Correct |
479 ms |
15004 KB |
Output is correct |
16 |
Correct |
636 ms |
14324 KB |
Output is correct |
17 |
Correct |
597 ms |
14104 KB |
Output is correct |
18 |
Correct |
306 ms |
15944 KB |
Output is correct |
19 |
Correct |
298 ms |
12996 KB |
Output is correct |
20 |
Correct |
726 ms |
14704 KB |
Output is correct |
21 |
Correct |
2000 ms |
17956 KB |
Output is correct |
22 |
Correct |
773 ms |
18240 KB |
Output is correct |
23 |
Correct |
841 ms |
17208 KB |
Output is correct |
24 |
Correct |
876 ms |
17172 KB |
Output is correct |
25 |
Correct |
613 ms |
19080 KB |
Output is correct |
26 |
Correct |
1028 ms |
17568 KB |
Output is correct |
27 |
Correct |
974 ms |
17516 KB |
Output is correct |
28 |
Correct |
254 ms |
20076 KB |
Output is correct |
29 |
Correct |
300 ms |
15988 KB |
Output is correct |
30 |
Correct |
1336 ms |
18208 KB |
Output is correct |
31 |
Correct |
1851 ms |
17996 KB |
Output is correct |
32 |
Correct |
1249 ms |
18080 KB |
Output is correct |
33 |
Correct |
549 ms |
17068 KB |
Output is correct |
34 |
Correct |
875 ms |
17076 KB |
Output is correct |
35 |
Correct |
996 ms |
17640 KB |
Output is correct |
36 |
Correct |
238 ms |
16012 KB |
Output is correct |
37 |
Correct |
1679 ms |
18152 KB |
Output is correct |
38 |
Correct |
320 ms |
16056 KB |
Output is correct |
39 |
Correct |
820 ms |
17316 KB |
Output is correct |
40 |
Correct |
876 ms |
16984 KB |
Output is correct |
41 |
Correct |
1162 ms |
11944 KB |
Output is correct |
42 |
Correct |
407 ms |
11864 KB |
Output is correct |
43 |
Correct |
166 ms |
11940 KB |
Output is correct |
44 |
Correct |
251 ms |
11880 KB |
Output is correct |
45 |
Correct |
94 ms |
11872 KB |
Output is correct |
46 |
Correct |
344 ms |
11932 KB |
Output is correct |
47 |
Correct |
328 ms |
11952 KB |
Output is correct |
48 |
Correct |
44 ms |
11928 KB |
Output is correct |
49 |
Correct |
47 ms |
11872 KB |
Output is correct |
50 |
Correct |
608 ms |
11908 KB |
Output is correct |
51 |
Correct |
1148 ms |
11872 KB |
Output is correct |
52 |
Correct |
252 ms |
11872 KB |
Output is correct |
53 |
Correct |
85 ms |
11840 KB |
Output is correct |
54 |
Correct |
190 ms |
11996 KB |
Output is correct |
55 |
Correct |
299 ms |
11872 KB |
Output is correct |
56 |
Correct |
41 ms |
11872 KB |
Output is correct |
57 |
Correct |
1120 ms |
11864 KB |
Output is correct |
58 |
Correct |
50 ms |
11872 KB |
Output is correct |
59 |
Correct |
145 ms |
11932 KB |
Output is correct |
60 |
Correct |
180 ms |
11944 KB |
Output is correct |
61 |
Correct |
84 ms |
11948 KB |
Output is correct |
62 |
Correct |
350 ms |
11880 KB |
Output is correct |
63 |
Correct |
312 ms |
11836 KB |
Output is correct |
64 |
Correct |
41 ms |
11872 KB |
Output is correct |
65 |
Correct |
349 ms |
11852 KB |
Output is correct |
66 |
Correct |
332 ms |
11956 KB |
Output is correct |
67 |
Correct |
344 ms |
11948 KB |
Output is correct |
68 |
Correct |
332 ms |
12000 KB |
Output is correct |
69 |
Correct |
345 ms |
11872 KB |
Output is correct |
70 |
Correct |
326 ms |
11872 KB |
Output is correct |
71 |
Execution timed out |
2080 ms |
10840 KB |
Time limit exceeded |
72 |
Halted |
0 ms |
0 KB |
- |