#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pll pair<ll,ll>
#define fs first
#define sc second
const int mxn = pow(3,13);
int ans[mxn];
void solve(){
int n,q;
cin>>n>>q;
int arr[1<<n];
for(auto &i:arr){
char c;
cin>>c;
i = c-'0';
}
for(int i = 0;i<(1<<n);i++){
for(int j = 0;j<(1<<n);j++){
int total = 0;
int p = 1;
for(int k = 0;k<n;k++){
if(j&(1<<k))total += p*2;
else if(i&(1<<k))total += p;
p *= 3;
}
ans[total] += arr[i];
}
}
while(q--){
string s;
cin>>s;
int p = 1;
int t = 0;
reverse(s.begin(),s.end());
for(int i = 0;i<n;i++){
if(s[i] == '?')t += p*2;
else if(s[i] == '1')t += p;
p *= 3;
}
cout<<ans[t]<<'\n';
}
}
int main(){
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int t = 1;
while(t--)solve();
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
480 KB |
Output is correct |
2 |
Correct |
16 ms |
468 KB |
Output is correct |
3 |
Correct |
16 ms |
536 KB |
Output is correct |
4 |
Correct |
17 ms |
560 KB |
Output is correct |
5 |
Correct |
17 ms |
476 KB |
Output is correct |
6 |
Correct |
16 ms |
468 KB |
Output is correct |
7 |
Correct |
21 ms |
564 KB |
Output is correct |
8 |
Correct |
17 ms |
480 KB |
Output is correct |
9 |
Correct |
16 ms |
564 KB |
Output is correct |
10 |
Correct |
16 ms |
564 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
480 KB |
Output is correct |
2 |
Correct |
16 ms |
468 KB |
Output is correct |
3 |
Correct |
16 ms |
536 KB |
Output is correct |
4 |
Correct |
17 ms |
560 KB |
Output is correct |
5 |
Correct |
17 ms |
476 KB |
Output is correct |
6 |
Correct |
16 ms |
468 KB |
Output is correct |
7 |
Correct |
21 ms |
564 KB |
Output is correct |
8 |
Correct |
17 ms |
480 KB |
Output is correct |
9 |
Correct |
16 ms |
564 KB |
Output is correct |
10 |
Correct |
16 ms |
564 KB |
Output is correct |
11 |
Correct |
226 ms |
4744 KB |
Output is correct |
12 |
Correct |
239 ms |
4236 KB |
Output is correct |
13 |
Correct |
189 ms |
3404 KB |
Output is correct |
14 |
Correct |
189 ms |
3548 KB |
Output is correct |
15 |
Correct |
209 ms |
4484 KB |
Output is correct |
16 |
Correct |
208 ms |
3724 KB |
Output is correct |
17 |
Correct |
209 ms |
3660 KB |
Output is correct |
18 |
Correct |
159 ms |
5548 KB |
Output is correct |
19 |
Correct |
165 ms |
2548 KB |
Output is correct |
20 |
Correct |
207 ms |
4312 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
480 KB |
Output is correct |
2 |
Correct |
16 ms |
468 KB |
Output is correct |
3 |
Correct |
16 ms |
536 KB |
Output is correct |
4 |
Correct |
17 ms |
560 KB |
Output is correct |
5 |
Correct |
17 ms |
476 KB |
Output is correct |
6 |
Correct |
16 ms |
468 KB |
Output is correct |
7 |
Correct |
21 ms |
564 KB |
Output is correct |
8 |
Correct |
17 ms |
480 KB |
Output is correct |
9 |
Correct |
16 ms |
564 KB |
Output is correct |
10 |
Correct |
16 ms |
564 KB |
Output is correct |
11 |
Correct |
226 ms |
4744 KB |
Output is correct |
12 |
Correct |
239 ms |
4236 KB |
Output is correct |
13 |
Correct |
189 ms |
3404 KB |
Output is correct |
14 |
Correct |
189 ms |
3548 KB |
Output is correct |
15 |
Correct |
209 ms |
4484 KB |
Output is correct |
16 |
Correct |
208 ms |
3724 KB |
Output is correct |
17 |
Correct |
209 ms |
3660 KB |
Output is correct |
18 |
Correct |
159 ms |
5548 KB |
Output is correct |
19 |
Correct |
165 ms |
2548 KB |
Output is correct |
20 |
Correct |
207 ms |
4312 KB |
Output is correct |
21 |
Execution timed out |
2061 ms |
5720 KB |
Time limit exceeded |
22 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
480 KB |
Output is correct |
2 |
Correct |
16 ms |
468 KB |
Output is correct |
3 |
Correct |
16 ms |
536 KB |
Output is correct |
4 |
Correct |
17 ms |
560 KB |
Output is correct |
5 |
Correct |
17 ms |
476 KB |
Output is correct |
6 |
Correct |
16 ms |
468 KB |
Output is correct |
7 |
Correct |
21 ms |
564 KB |
Output is correct |
8 |
Correct |
17 ms |
480 KB |
Output is correct |
9 |
Correct |
16 ms |
564 KB |
Output is correct |
10 |
Correct |
16 ms |
564 KB |
Output is correct |
11 |
Runtime error |
22 ms |
10420 KB |
Execution killed with signal 11 |
12 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
480 KB |
Output is correct |
2 |
Correct |
16 ms |
468 KB |
Output is correct |
3 |
Correct |
16 ms |
536 KB |
Output is correct |
4 |
Correct |
17 ms |
560 KB |
Output is correct |
5 |
Correct |
17 ms |
476 KB |
Output is correct |
6 |
Correct |
16 ms |
468 KB |
Output is correct |
7 |
Correct |
21 ms |
564 KB |
Output is correct |
8 |
Correct |
17 ms |
480 KB |
Output is correct |
9 |
Correct |
16 ms |
564 KB |
Output is correct |
10 |
Correct |
16 ms |
564 KB |
Output is correct |
11 |
Correct |
226 ms |
4744 KB |
Output is correct |
12 |
Correct |
239 ms |
4236 KB |
Output is correct |
13 |
Correct |
189 ms |
3404 KB |
Output is correct |
14 |
Correct |
189 ms |
3548 KB |
Output is correct |
15 |
Correct |
209 ms |
4484 KB |
Output is correct |
16 |
Correct |
208 ms |
3724 KB |
Output is correct |
17 |
Correct |
209 ms |
3660 KB |
Output is correct |
18 |
Correct |
159 ms |
5548 KB |
Output is correct |
19 |
Correct |
165 ms |
2548 KB |
Output is correct |
20 |
Correct |
207 ms |
4312 KB |
Output is correct |
21 |
Execution timed out |
2061 ms |
5720 KB |
Time limit exceeded |
22 |
Halted |
0 ms |
0 KB |
- |