#include <bits/stdc++.h>
using namespace std;
#define int long long
const int INF = INT64_MAX;
int arr[8192];
char str[13];
int L;
int ask(int perm){
int idx = 0;
for(int x=0;x<L;x++){
if(str[x]=='1')idx|=(1<<x);
else if(str[x]=='?'){idx|=((perm&1)<<x);perm>>=1;}
}
return arr[idx];
}
int32_t main(){
cin.tie(nullptr);
ios::sync_with_stdio(false);
int q;
cin >> L >> q;
for(int i=0;i<(1<<L);i++){
char a;cin>>a;a-='0';
arr[i]=a;
}
map<string,int> memo;
for (int i = 0; i < q; i++) {
for(int j=L-1;j>=0;j--)cin>>str[j];
if(memo.count(str)){cout<<memo[str]<<'\n';continue;}
int n = count(str, str+L,'?');
int ans = 0;
for(int perm = 0;perm<(1<<n);perm++){
ans+=ask(perm);
}
cout << ans << '\n';
memo[str]=ans;
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
2 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
600 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
2 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
600 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
309 ms |
4444 KB |
Output is correct |
12 |
Correct |
396 ms |
3992 KB |
Output is correct |
13 |
Correct |
487 ms |
3920 KB |
Output is correct |
14 |
Correct |
465 ms |
3716 KB |
Output is correct |
15 |
Correct |
451 ms |
4688 KB |
Output is correct |
16 |
Correct |
530 ms |
4824 KB |
Output is correct |
17 |
Correct |
640 ms |
8112 KB |
Output is correct |
18 |
Correct |
183 ms |
5348 KB |
Output is correct |
19 |
Correct |
296 ms |
2676 KB |
Output is correct |
20 |
Correct |
387 ms |
4164 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
2 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
600 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
309 ms |
4444 KB |
Output is correct |
12 |
Correct |
396 ms |
3992 KB |
Output is correct |
13 |
Correct |
487 ms |
3920 KB |
Output is correct |
14 |
Correct |
465 ms |
3716 KB |
Output is correct |
15 |
Correct |
451 ms |
4688 KB |
Output is correct |
16 |
Correct |
530 ms |
4824 KB |
Output is correct |
17 |
Correct |
640 ms |
8112 KB |
Output is correct |
18 |
Correct |
183 ms |
5348 KB |
Output is correct |
19 |
Correct |
296 ms |
2676 KB |
Output is correct |
20 |
Correct |
387 ms |
4164 KB |
Output is correct |
21 |
Correct |
443 ms |
4436 KB |
Output is correct |
22 |
Correct |
548 ms |
5156 KB |
Output is correct |
23 |
Correct |
970 ms |
20652 KB |
Output is correct |
24 |
Correct |
757 ms |
10580 KB |
Output is correct |
25 |
Correct |
811 ms |
8528 KB |
Output is correct |
26 |
Correct |
1381 ms |
30600 KB |
Output is correct |
27 |
Execution timed out |
2063 ms |
65536 KB |
Time limit exceeded |
28 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
2 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
600 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Runtime error |
1 ms |
600 KB |
Execution killed with signal 11 |
12 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
2 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
1 ms |
600 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
309 ms |
4444 KB |
Output is correct |
12 |
Correct |
396 ms |
3992 KB |
Output is correct |
13 |
Correct |
487 ms |
3920 KB |
Output is correct |
14 |
Correct |
465 ms |
3716 KB |
Output is correct |
15 |
Correct |
451 ms |
4688 KB |
Output is correct |
16 |
Correct |
530 ms |
4824 KB |
Output is correct |
17 |
Correct |
640 ms |
8112 KB |
Output is correct |
18 |
Correct |
183 ms |
5348 KB |
Output is correct |
19 |
Correct |
296 ms |
2676 KB |
Output is correct |
20 |
Correct |
387 ms |
4164 KB |
Output is correct |
21 |
Correct |
443 ms |
4436 KB |
Output is correct |
22 |
Correct |
548 ms |
5156 KB |
Output is correct |
23 |
Correct |
970 ms |
20652 KB |
Output is correct |
24 |
Correct |
757 ms |
10580 KB |
Output is correct |
25 |
Correct |
811 ms |
8528 KB |
Output is correct |
26 |
Correct |
1381 ms |
30600 KB |
Output is correct |
27 |
Execution timed out |
2063 ms |
65536 KB |
Time limit exceeded |
28 |
Halted |
0 ms |
0 KB |
- |