#include<iostream>
#include<vector>
#include<algorithm>
#define ep emplace
#define eb emplace_back
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef pair<int,int>pi;
typedef pair<ll,ll>pl;
const int inf=1e9+7;
const ll INF=1e18+7;
const int cut=9;
int sum[20000];
int p3[20];
int ans[1000010];
pair<pair<short,short>,int>qid[1000010];
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int l,q;
cin>>l>>q;
string s;
cin>>s;
if(l<cut)
{
l=cut;
while((int)s.size()<1<<l)
s.push_back('0');
}
p3[0]=1;
for(int i=1;i<15;i++)
p3[i]=p3[i-1]*3;
for(int i=0;i<q;i++)
{
string t;
cin>>t;
reverse(all(t));
while((int)t.size()<l)
t.push_back('0');
int id=0;
for(int j=0;j<cut;j++)
{
if(t[j]=='?')
id+=p3[j]*2;
else
id+=((char)t[j]-'0')*p3[j];
}
qid[i].se=id;
int id2=0,id3=0;
for(int j=cut;j<l;j++)
{
if(t[j]=='?')
id3+=1<<(j-cut);
else
id2+=((char)t[j]-'0')*(1<<(j-cut));
}
qid[i].fi.fi=id2;
qid[i].fi.se=id3;
}
for(int i=0;i<1<<(l-cut);i++)
{
vector<int>v;
for(int j=0;j<1<<cut;j++)
{
int id=0;
for(int k=0;k<cut;k++)
id+=(j>>k&1)*p3[k];
sum[id]=(char)s[i*(1<<cut)+j]-'0';
v.eb(id);
}
for(int li=0;li<cut;li++)
{
for(int k=0,m=v.size();k<m;k++)
{
int j=v[k];
int cut=j%p3[li+1]/p3[li];
sum[j+(2-cut)*p3[li]]+=sum[j];
if(cut==1)
v.eb(j+p3[li]);
}
}
for(int j=0;j<q;j++)
if(((qid[j].fi.fi^i)&~qid[j].fi.se)==0)
ans[j]+=sum[qid[j].se];
for(int&t:v)
sum[t]=0;
}
for(int i=0;i<q;i++)
cout<<ans[i]<<'\n';
cout.flush();
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
684 KB |
Output is correct |
2 |
Correct |
3 ms |
684 KB |
Output is correct |
3 |
Correct |
2 ms |
684 KB |
Output is correct |
4 |
Correct |
3 ms |
684 KB |
Output is correct |
5 |
Correct |
3 ms |
684 KB |
Output is correct |
6 |
Correct |
3 ms |
684 KB |
Output is correct |
7 |
Correct |
2 ms |
684 KB |
Output is correct |
8 |
Correct |
2 ms |
684 KB |
Output is correct |
9 |
Correct |
2 ms |
684 KB |
Output is correct |
10 |
Correct |
2 ms |
684 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
684 KB |
Output is correct |
2 |
Correct |
3 ms |
684 KB |
Output is correct |
3 |
Correct |
2 ms |
684 KB |
Output is correct |
4 |
Correct |
3 ms |
684 KB |
Output is correct |
5 |
Correct |
3 ms |
684 KB |
Output is correct |
6 |
Correct |
3 ms |
684 KB |
Output is correct |
7 |
Correct |
2 ms |
684 KB |
Output is correct |
8 |
Correct |
2 ms |
684 KB |
Output is correct |
9 |
Correct |
2 ms |
684 KB |
Output is correct |
10 |
Correct |
2 ms |
684 KB |
Output is correct |
11 |
Correct |
237 ms |
16328 KB |
Output is correct |
12 |
Correct |
255 ms |
15944 KB |
Output is correct |
13 |
Correct |
226 ms |
15304 KB |
Output is correct |
14 |
Correct |
232 ms |
15304 KB |
Output is correct |
15 |
Correct |
235 ms |
16328 KB |
Output is correct |
16 |
Correct |
242 ms |
15556 KB |
Output is correct |
17 |
Correct |
234 ms |
15484 KB |
Output is correct |
18 |
Correct |
189 ms |
17380 KB |
Output is correct |
19 |
Correct |
188 ms |
14452 KB |
Output is correct |
20 |
Correct |
244 ms |
16068 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
684 KB |
Output is correct |
2 |
Correct |
3 ms |
684 KB |
Output is correct |
3 |
Correct |
2 ms |
684 KB |
Output is correct |
4 |
Correct |
3 ms |
684 KB |
Output is correct |
5 |
Correct |
3 ms |
684 KB |
Output is correct |
6 |
Correct |
3 ms |
684 KB |
Output is correct |
7 |
Correct |
2 ms |
684 KB |
Output is correct |
8 |
Correct |
2 ms |
684 KB |
Output is correct |
9 |
Correct |
2 ms |
684 KB |
Output is correct |
10 |
Correct |
2 ms |
684 KB |
Output is correct |
11 |
Correct |
237 ms |
16328 KB |
Output is correct |
12 |
Correct |
255 ms |
15944 KB |
Output is correct |
13 |
Correct |
226 ms |
15304 KB |
Output is correct |
14 |
Correct |
232 ms |
15304 KB |
Output is correct |
15 |
Correct |
235 ms |
16328 KB |
Output is correct |
16 |
Correct |
242 ms |
15556 KB |
Output is correct |
17 |
Correct |
234 ms |
15484 KB |
Output is correct |
18 |
Correct |
189 ms |
17380 KB |
Output is correct |
19 |
Correct |
188 ms |
14452 KB |
Output is correct |
20 |
Correct |
244 ms |
16068 KB |
Output is correct |
21 |
Correct |
322 ms |
16296 KB |
Output is correct |
22 |
Correct |
356 ms |
16680 KB |
Output is correct |
23 |
Correct |
289 ms |
15528 KB |
Output is correct |
24 |
Correct |
292 ms |
15400 KB |
Output is correct |
25 |
Correct |
349 ms |
17320 KB |
Output is correct |
26 |
Correct |
331 ms |
15784 KB |
Output is correct |
27 |
Correct |
313 ms |
15784 KB |
Output is correct |
28 |
Correct |
240 ms |
18344 KB |
Output is correct |
29 |
Correct |
222 ms |
14376 KB |
Output is correct |
30 |
Correct |
330 ms |
16632 KB |
Output is correct |
31 |
Correct |
325 ms |
16296 KB |
Output is correct |
32 |
Correct |
307 ms |
16400 KB |
Output is correct |
33 |
Correct |
273 ms |
15272 KB |
Output is correct |
34 |
Correct |
289 ms |
15288 KB |
Output is correct |
35 |
Correct |
315 ms |
15816 KB |
Output is correct |
36 |
Correct |
206 ms |
14376 KB |
Output is correct |
37 |
Correct |
331 ms |
16476 KB |
Output is correct |
38 |
Correct |
212 ms |
14376 KB |
Output is correct |
39 |
Correct |
297 ms |
15656 KB |
Output is correct |
40 |
Correct |
311 ms |
15340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
684 KB |
Output is correct |
2 |
Correct |
3 ms |
684 KB |
Output is correct |
3 |
Correct |
2 ms |
684 KB |
Output is correct |
4 |
Correct |
3 ms |
684 KB |
Output is correct |
5 |
Correct |
3 ms |
684 KB |
Output is correct |
6 |
Correct |
3 ms |
684 KB |
Output is correct |
7 |
Correct |
2 ms |
684 KB |
Output is correct |
8 |
Correct |
2 ms |
684 KB |
Output is correct |
9 |
Correct |
2 ms |
684 KB |
Output is correct |
10 |
Correct |
2 ms |
684 KB |
Output is correct |
11 |
Correct |
1410 ms |
2708 KB |
Output is correct |
12 |
Correct |
1419 ms |
2584 KB |
Output is correct |
13 |
Correct |
1380 ms |
2460 KB |
Output is correct |
14 |
Correct |
1388 ms |
2460 KB |
Output is correct |
15 |
Correct |
1488 ms |
2576 KB |
Output is correct |
16 |
Correct |
1404 ms |
2460 KB |
Output is correct |
17 |
Correct |
1407 ms |
2460 KB |
Output is correct |
18 |
Correct |
1406 ms |
2704 KB |
Output is correct |
19 |
Correct |
1369 ms |
2460 KB |
Output is correct |
20 |
Correct |
1423 ms |
2568 KB |
Output is correct |
21 |
Correct |
1410 ms |
2576 KB |
Output is correct |
22 |
Correct |
1406 ms |
2460 KB |
Output is correct |
23 |
Correct |
1374 ms |
2460 KB |
Output is correct |
24 |
Correct |
1378 ms |
2460 KB |
Output is correct |
25 |
Correct |
1398 ms |
2460 KB |
Output is correct |
26 |
Correct |
1368 ms |
2460 KB |
Output is correct |
27 |
Correct |
1408 ms |
2572 KB |
Output is correct |
28 |
Correct |
1377 ms |
2460 KB |
Output is correct |
29 |
Correct |
1380 ms |
2460 KB |
Output is correct |
30 |
Correct |
1382 ms |
2460 KB |
Output is correct |
31 |
Correct |
1396 ms |
2460 KB |
Output is correct |
32 |
Correct |
1392 ms |
2460 KB |
Output is correct |
33 |
Correct |
1410 ms |
2460 KB |
Output is correct |
34 |
Correct |
1364 ms |
2460 KB |
Output is correct |
35 |
Correct |
1483 ms |
2460 KB |
Output is correct |
36 |
Correct |
1439 ms |
2460 KB |
Output is correct |
37 |
Correct |
1430 ms |
2656 KB |
Output is correct |
38 |
Correct |
1434 ms |
2588 KB |
Output is correct |
39 |
Correct |
1431 ms |
2460 KB |
Output is correct |
40 |
Correct |
1446 ms |
2460 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
684 KB |
Output is correct |
2 |
Correct |
3 ms |
684 KB |
Output is correct |
3 |
Correct |
2 ms |
684 KB |
Output is correct |
4 |
Correct |
3 ms |
684 KB |
Output is correct |
5 |
Correct |
3 ms |
684 KB |
Output is correct |
6 |
Correct |
3 ms |
684 KB |
Output is correct |
7 |
Correct |
2 ms |
684 KB |
Output is correct |
8 |
Correct |
2 ms |
684 KB |
Output is correct |
9 |
Correct |
2 ms |
684 KB |
Output is correct |
10 |
Correct |
2 ms |
684 KB |
Output is correct |
11 |
Correct |
237 ms |
16328 KB |
Output is correct |
12 |
Correct |
255 ms |
15944 KB |
Output is correct |
13 |
Correct |
226 ms |
15304 KB |
Output is correct |
14 |
Correct |
232 ms |
15304 KB |
Output is correct |
15 |
Correct |
235 ms |
16328 KB |
Output is correct |
16 |
Correct |
242 ms |
15556 KB |
Output is correct |
17 |
Correct |
234 ms |
15484 KB |
Output is correct |
18 |
Correct |
189 ms |
17380 KB |
Output is correct |
19 |
Correct |
188 ms |
14452 KB |
Output is correct |
20 |
Correct |
244 ms |
16068 KB |
Output is correct |
21 |
Correct |
322 ms |
16296 KB |
Output is correct |
22 |
Correct |
356 ms |
16680 KB |
Output is correct |
23 |
Correct |
289 ms |
15528 KB |
Output is correct |
24 |
Correct |
292 ms |
15400 KB |
Output is correct |
25 |
Correct |
349 ms |
17320 KB |
Output is correct |
26 |
Correct |
331 ms |
15784 KB |
Output is correct |
27 |
Correct |
313 ms |
15784 KB |
Output is correct |
28 |
Correct |
240 ms |
18344 KB |
Output is correct |
29 |
Correct |
222 ms |
14376 KB |
Output is correct |
30 |
Correct |
330 ms |
16632 KB |
Output is correct |
31 |
Correct |
325 ms |
16296 KB |
Output is correct |
32 |
Correct |
307 ms |
16400 KB |
Output is correct |
33 |
Correct |
273 ms |
15272 KB |
Output is correct |
34 |
Correct |
289 ms |
15288 KB |
Output is correct |
35 |
Correct |
315 ms |
15816 KB |
Output is correct |
36 |
Correct |
206 ms |
14376 KB |
Output is correct |
37 |
Correct |
331 ms |
16476 KB |
Output is correct |
38 |
Correct |
212 ms |
14376 KB |
Output is correct |
39 |
Correct |
297 ms |
15656 KB |
Output is correct |
40 |
Correct |
311 ms |
15340 KB |
Output is correct |
41 |
Correct |
1410 ms |
2708 KB |
Output is correct |
42 |
Correct |
1419 ms |
2584 KB |
Output is correct |
43 |
Correct |
1380 ms |
2460 KB |
Output is correct |
44 |
Correct |
1388 ms |
2460 KB |
Output is correct |
45 |
Correct |
1488 ms |
2576 KB |
Output is correct |
46 |
Correct |
1404 ms |
2460 KB |
Output is correct |
47 |
Correct |
1407 ms |
2460 KB |
Output is correct |
48 |
Correct |
1406 ms |
2704 KB |
Output is correct |
49 |
Correct |
1369 ms |
2460 KB |
Output is correct |
50 |
Correct |
1423 ms |
2568 KB |
Output is correct |
51 |
Correct |
1410 ms |
2576 KB |
Output is correct |
52 |
Correct |
1406 ms |
2460 KB |
Output is correct |
53 |
Correct |
1374 ms |
2460 KB |
Output is correct |
54 |
Correct |
1378 ms |
2460 KB |
Output is correct |
55 |
Correct |
1398 ms |
2460 KB |
Output is correct |
56 |
Correct |
1368 ms |
2460 KB |
Output is correct |
57 |
Correct |
1408 ms |
2572 KB |
Output is correct |
58 |
Correct |
1377 ms |
2460 KB |
Output is correct |
59 |
Correct |
1380 ms |
2460 KB |
Output is correct |
60 |
Correct |
1382 ms |
2460 KB |
Output is correct |
61 |
Correct |
1396 ms |
2460 KB |
Output is correct |
62 |
Correct |
1392 ms |
2460 KB |
Output is correct |
63 |
Correct |
1410 ms |
2460 KB |
Output is correct |
64 |
Correct |
1364 ms |
2460 KB |
Output is correct |
65 |
Correct |
1483 ms |
2460 KB |
Output is correct |
66 |
Correct |
1439 ms |
2460 KB |
Output is correct |
67 |
Correct |
1430 ms |
2656 KB |
Output is correct |
68 |
Correct |
1434 ms |
2588 KB |
Output is correct |
69 |
Correct |
1431 ms |
2460 KB |
Output is correct |
70 |
Correct |
1446 ms |
2460 KB |
Output is correct |
71 |
Execution timed out |
2078 ms |
13436 KB |
Time limit exceeded |
72 |
Halted |
0 ms |
0 KB |
- |