#include <bits/stdc++.h>
#define pb push_back
#define f first
#define sc second
using namespace std;
typedef long long int ll;
typedef string str;
const int p3[] = {1, 3, 9, 27, 81, 243, 729, 2187, 6561, 19683, 59049, 177147, 531441, 1594323, 4782969, 14348907};
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
int L, Q; cin >> L >> Q;
int* v = new int[1<<L];
for(int i = 0; i < (1<<L); i++){
char c; cin >> c;
v[i] = c-'0';
}
int* dp = new int[p3[L]];
fill(dp, dp+p3[L], 0);
for(int i = 0; i < (1<<L); i++){
int x = 0;
for(int j = 0; j < L; j++) if(i&(1<<j)) x+=p3[j];
dp[x]+=v[i];
}
for(int j = 0; j < L; j++) for(int i = 0; i < p3[L]; i++){
if((i/p3[j])%3 == 2){
dp[i]+=dp[i-p3[j]*2]+dp[i-p3[j]];
}
}
while(Q--){
str s; cin >> s;
reverse(s.begin(), s.end());
int x = 0;
for(int i = 0; i < L; i++){
if(s[i] == '?') x+=p3[i]*2;
else x+=(s[i]-'0')*p3[i];
}
cout << dp[x] << "\n";
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
468 KB |
Output is correct |
2 |
Correct |
4 ms |
468 KB |
Output is correct |
3 |
Correct |
5 ms |
580 KB |
Output is correct |
4 |
Correct |
4 ms |
468 KB |
Output is correct |
5 |
Correct |
4 ms |
584 KB |
Output is correct |
6 |
Correct |
4 ms |
580 KB |
Output is correct |
7 |
Correct |
4 ms |
584 KB |
Output is correct |
8 |
Correct |
4 ms |
588 KB |
Output is correct |
9 |
Correct |
5 ms |
468 KB |
Output is correct |
10 |
Correct |
4 ms |
468 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
468 KB |
Output is correct |
2 |
Correct |
4 ms |
468 KB |
Output is correct |
3 |
Correct |
5 ms |
580 KB |
Output is correct |
4 |
Correct |
4 ms |
468 KB |
Output is correct |
5 |
Correct |
4 ms |
584 KB |
Output is correct |
6 |
Correct |
4 ms |
580 KB |
Output is correct |
7 |
Correct |
4 ms |
584 KB |
Output is correct |
8 |
Correct |
4 ms |
588 KB |
Output is correct |
9 |
Correct |
5 ms |
468 KB |
Output is correct |
10 |
Correct |
4 ms |
468 KB |
Output is correct |
11 |
Correct |
199 ms |
11856 KB |
Output is correct |
12 |
Correct |
210 ms |
11584 KB |
Output is correct |
13 |
Correct |
178 ms |
10780 KB |
Output is correct |
14 |
Correct |
177 ms |
10872 KB |
Output is correct |
15 |
Correct |
212 ms |
11760 KB |
Output is correct |
16 |
Correct |
196 ms |
11136 KB |
Output is correct |
17 |
Correct |
196 ms |
10912 KB |
Output is correct |
18 |
Correct |
151 ms |
12836 KB |
Output is correct |
19 |
Correct |
161 ms |
9868 KB |
Output is correct |
20 |
Correct |
208 ms |
11460 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
468 KB |
Output is correct |
2 |
Correct |
4 ms |
468 KB |
Output is correct |
3 |
Correct |
5 ms |
580 KB |
Output is correct |
4 |
Correct |
4 ms |
468 KB |
Output is correct |
5 |
Correct |
4 ms |
584 KB |
Output is correct |
6 |
Correct |
4 ms |
580 KB |
Output is correct |
7 |
Correct |
4 ms |
584 KB |
Output is correct |
8 |
Correct |
4 ms |
588 KB |
Output is correct |
9 |
Correct |
5 ms |
468 KB |
Output is correct |
10 |
Correct |
4 ms |
468 KB |
Output is correct |
11 |
Correct |
199 ms |
11856 KB |
Output is correct |
12 |
Correct |
210 ms |
11584 KB |
Output is correct |
13 |
Correct |
178 ms |
10780 KB |
Output is correct |
14 |
Correct |
177 ms |
10872 KB |
Output is correct |
15 |
Correct |
212 ms |
11760 KB |
Output is correct |
16 |
Correct |
196 ms |
11136 KB |
Output is correct |
17 |
Correct |
196 ms |
10912 KB |
Output is correct |
18 |
Correct |
151 ms |
12836 KB |
Output is correct |
19 |
Correct |
161 ms |
9868 KB |
Output is correct |
20 |
Correct |
208 ms |
11460 KB |
Output is correct |
21 |
Correct |
340 ms |
24216 KB |
Output is correct |
22 |
Correct |
352 ms |
24376 KB |
Output is correct |
23 |
Correct |
350 ms |
23380 KB |
Output is correct |
24 |
Correct |
343 ms |
23252 KB |
Output is correct |
25 |
Correct |
340 ms |
25268 KB |
Output is correct |
26 |
Correct |
408 ms |
23820 KB |
Output is correct |
27 |
Correct |
369 ms |
23772 KB |
Output is correct |
28 |
Correct |
291 ms |
26288 KB |
Output is correct |
29 |
Correct |
292 ms |
22292 KB |
Output is correct |
30 |
Correct |
348 ms |
24440 KB |
Output is correct |
31 |
Correct |
363 ms |
24332 KB |
Output is correct |
32 |
Correct |
370 ms |
24384 KB |
Output is correct |
33 |
Correct |
313 ms |
23200 KB |
Output is correct |
34 |
Correct |
347 ms |
23260 KB |
Output is correct |
35 |
Correct |
396 ms |
23712 KB |
Output is correct |
36 |
Correct |
298 ms |
22312 KB |
Output is correct |
37 |
Correct |
339 ms |
24220 KB |
Output is correct |
38 |
Correct |
292 ms |
22196 KB |
Output is correct |
39 |
Correct |
344 ms |
23476 KB |
Output is correct |
40 |
Correct |
343 ms |
23256 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
468 KB |
Output is correct |
2 |
Correct |
4 ms |
468 KB |
Output is correct |
3 |
Correct |
5 ms |
580 KB |
Output is correct |
4 |
Correct |
4 ms |
468 KB |
Output is correct |
5 |
Correct |
4 ms |
584 KB |
Output is correct |
6 |
Correct |
4 ms |
580 KB |
Output is correct |
7 |
Correct |
4 ms |
584 KB |
Output is correct |
8 |
Correct |
4 ms |
588 KB |
Output is correct |
9 |
Correct |
5 ms |
468 KB |
Output is correct |
10 |
Correct |
4 ms |
468 KB |
Output is correct |
11 |
Runtime error |
19 ms |
10188 KB |
Execution killed with signal 6 |
12 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
468 KB |
Output is correct |
2 |
Correct |
4 ms |
468 KB |
Output is correct |
3 |
Correct |
5 ms |
580 KB |
Output is correct |
4 |
Correct |
4 ms |
468 KB |
Output is correct |
5 |
Correct |
4 ms |
584 KB |
Output is correct |
6 |
Correct |
4 ms |
580 KB |
Output is correct |
7 |
Correct |
4 ms |
584 KB |
Output is correct |
8 |
Correct |
4 ms |
588 KB |
Output is correct |
9 |
Correct |
5 ms |
468 KB |
Output is correct |
10 |
Correct |
4 ms |
468 KB |
Output is correct |
11 |
Correct |
199 ms |
11856 KB |
Output is correct |
12 |
Correct |
210 ms |
11584 KB |
Output is correct |
13 |
Correct |
178 ms |
10780 KB |
Output is correct |
14 |
Correct |
177 ms |
10872 KB |
Output is correct |
15 |
Correct |
212 ms |
11760 KB |
Output is correct |
16 |
Correct |
196 ms |
11136 KB |
Output is correct |
17 |
Correct |
196 ms |
10912 KB |
Output is correct |
18 |
Correct |
151 ms |
12836 KB |
Output is correct |
19 |
Correct |
161 ms |
9868 KB |
Output is correct |
20 |
Correct |
208 ms |
11460 KB |
Output is correct |
21 |
Correct |
340 ms |
24216 KB |
Output is correct |
22 |
Correct |
352 ms |
24376 KB |
Output is correct |
23 |
Correct |
350 ms |
23380 KB |
Output is correct |
24 |
Correct |
343 ms |
23252 KB |
Output is correct |
25 |
Correct |
340 ms |
25268 KB |
Output is correct |
26 |
Correct |
408 ms |
23820 KB |
Output is correct |
27 |
Correct |
369 ms |
23772 KB |
Output is correct |
28 |
Correct |
291 ms |
26288 KB |
Output is correct |
29 |
Correct |
292 ms |
22292 KB |
Output is correct |
30 |
Correct |
348 ms |
24440 KB |
Output is correct |
31 |
Correct |
363 ms |
24332 KB |
Output is correct |
32 |
Correct |
370 ms |
24384 KB |
Output is correct |
33 |
Correct |
313 ms |
23200 KB |
Output is correct |
34 |
Correct |
347 ms |
23260 KB |
Output is correct |
35 |
Correct |
396 ms |
23712 KB |
Output is correct |
36 |
Correct |
298 ms |
22312 KB |
Output is correct |
37 |
Correct |
339 ms |
24220 KB |
Output is correct |
38 |
Correct |
292 ms |
22196 KB |
Output is correct |
39 |
Correct |
344 ms |
23476 KB |
Output is correct |
40 |
Correct |
343 ms |
23256 KB |
Output is correct |
41 |
Runtime error |
19 ms |
10188 KB |
Execution killed with signal 6 |
42 |
Halted |
0 ms |
0 KB |
- |