#include<bits/stdc++.h>
#define st first
#define nd second
#define pb push_back
#define ppb pop_back
#define umax(x,y) x=max(x,y)
#define umin(x,y) x=min(x,y)
#define ll long long
#define ii pair<int,int>
#define iii pair<int,ii>
#define sz(x) ((int) x.size())
#define orta ((bas+son)>>1)
#define all(x) x.begin(),x.end()
#define dbgs(x) cerr<<(#x)<<" --> "<<(x)<<" "
#define dbg(x) cerr<<(#x)<<" --> "<<(x)<<endl;getchar()
#define pw(x) (1<<(x))
#define inf 100000000000000
#define MOD 1000000007
#define N 3005
#define MAX 10000006
#define LOG 22
#define L 7
#define R 13
using namespace std;
int n,q,l,Qno,Right;
int cnt[1594325],ans[pw(20)+5];
int po3[20],pos[1594325];
char val[pw(20)+5],s[pw(20)+5];
vector<ii> queries[pw(L)];
bool oops[1594325];
int get_2_rep(int val) {
int res=0;
int curpw=1;
while(val) {
res+=curpw*(val%3);
val/=3;
curpw*=2;
}
return res;
}
int get_2(int val) {
int cur=0;
while(val) {
if(val%3==2) return cur;
cur++;
val/=3;
}
return -1;
}
void do_dp(int value) {
for(int i=0;i<1594323;i++) {
if(oops[i]) cnt[i]=val[value*pw(R)+pos[i]];
else cnt[i]=cnt[i-po3[pos[i]]]+cnt[i-2*po3[pos[i]]];
}
}
void pre_cal() {
for(int i=0;i<1594323;i++) {
pos[i]=get_2(i);
if(pos[i]==-1) {
oops[i]=true;
pos[i]=get_2_rep(i);
}
}
}
void back_track(int cur,int val) {
if(cur==L) {
queries[val].pb({Right,Qno});
return ;
}
if(s[cur]=='?') {
back_track(cur+1,val);
back_track(cur+1,val+pw(cur));
}
else back_track(cur+1,val+pw(cur)*(s[cur]=='1'));
}
int get_value(int bas,int son) {
int res=0;
for(int i=bas;i<=son;i++) {
res=res*3+(s[i]=='?'?2:(s[i]-'0'));
}
return res;
}
int main() {
//freopen("input.txt","r",stdin);
po3[0]=1;
for(int i=1;i<=15;i++) po3[i]=po3[i-1]*3;
scanf("%d %d",&l,&q);
n=pw(l);
scanf("%s",s);
for(int i=0;i<n;i++) val[i]=s[i]-'0';
for(int i=1;i<=q;i++) {
scanf("%s",s+20-l);
for(int i=0;i<20-l;i++) s[i]='0';
Right=get_value(7,19);
Qno=i;
back_track(0,0);
}
pre_cal();
for(int i=0;i<pw(L);i++) {
if(!sz(queries[i])) continue ;
do_dp(i);
for(ii Q:queries[i]) { // Q.st-->right Q.nd-->quno
ans[Q.nd]+=cnt[Q.st];
}
}
for(int i=1;i<=q;i++) printf("%d\n",ans[i]);
}
Compilation message
snake_escaping.cpp: In function 'int main()':
snake_escaping.cpp:141:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d",&l,&q);
~~~~~^~~~~~~~~~~~~~~
snake_escaping.cpp:145:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%s",s);
~~~~~^~~~~~~~
snake_escaping.cpp:151:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%s",s+20-l);
~~~~~^~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
29 ms |
13048 KB |
Output is correct |
2 |
Correct |
29 ms |
13048 KB |
Output is correct |
3 |
Correct |
33 ms |
13084 KB |
Output is correct |
4 |
Correct |
29 ms |
13144 KB |
Output is correct |
5 |
Correct |
33 ms |
13400 KB |
Output is correct |
6 |
Correct |
31 ms |
13400 KB |
Output is correct |
7 |
Correct |
29 ms |
13400 KB |
Output is correct |
8 |
Correct |
28 ms |
13400 KB |
Output is correct |
9 |
Correct |
29 ms |
13400 KB |
Output is correct |
10 |
Correct |
27 ms |
13400 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
29 ms |
13048 KB |
Output is correct |
2 |
Correct |
29 ms |
13048 KB |
Output is correct |
3 |
Correct |
33 ms |
13084 KB |
Output is correct |
4 |
Correct |
29 ms |
13144 KB |
Output is correct |
5 |
Correct |
33 ms |
13400 KB |
Output is correct |
6 |
Correct |
31 ms |
13400 KB |
Output is correct |
7 |
Correct |
29 ms |
13400 KB |
Output is correct |
8 |
Correct |
28 ms |
13400 KB |
Output is correct |
9 |
Correct |
29 ms |
13400 KB |
Output is correct |
10 |
Correct |
27 ms |
13400 KB |
Output is correct |
11 |
Correct |
322 ms |
29008 KB |
Output is correct |
12 |
Correct |
370 ms |
29008 KB |
Output is correct |
13 |
Correct |
349 ms |
29008 KB |
Output is correct |
14 |
Correct |
314 ms |
29008 KB |
Output is correct |
15 |
Correct |
387 ms |
29304 KB |
Output is correct |
16 |
Correct |
389 ms |
29304 KB |
Output is correct |
17 |
Correct |
383 ms |
29304 KB |
Output is correct |
18 |
Correct |
317 ms |
30176 KB |
Output is correct |
19 |
Correct |
291 ms |
30176 KB |
Output is correct |
20 |
Correct |
394 ms |
30176 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
29 ms |
13048 KB |
Output is correct |
2 |
Correct |
29 ms |
13048 KB |
Output is correct |
3 |
Correct |
33 ms |
13084 KB |
Output is correct |
4 |
Correct |
29 ms |
13144 KB |
Output is correct |
5 |
Correct |
33 ms |
13400 KB |
Output is correct |
6 |
Correct |
31 ms |
13400 KB |
Output is correct |
7 |
Correct |
29 ms |
13400 KB |
Output is correct |
8 |
Correct |
28 ms |
13400 KB |
Output is correct |
9 |
Correct |
29 ms |
13400 KB |
Output is correct |
10 |
Correct |
27 ms |
13400 KB |
Output is correct |
11 |
Correct |
322 ms |
29008 KB |
Output is correct |
12 |
Correct |
370 ms |
29008 KB |
Output is correct |
13 |
Correct |
349 ms |
29008 KB |
Output is correct |
14 |
Correct |
314 ms |
29008 KB |
Output is correct |
15 |
Correct |
387 ms |
29304 KB |
Output is correct |
16 |
Correct |
389 ms |
29304 KB |
Output is correct |
17 |
Correct |
383 ms |
29304 KB |
Output is correct |
18 |
Correct |
317 ms |
30176 KB |
Output is correct |
19 |
Correct |
291 ms |
30176 KB |
Output is correct |
20 |
Correct |
394 ms |
30176 KB |
Output is correct |
21 |
Correct |
429 ms |
30176 KB |
Output is correct |
22 |
Correct |
477 ms |
30176 KB |
Output is correct |
23 |
Correct |
397 ms |
30176 KB |
Output is correct |
24 |
Correct |
371 ms |
30176 KB |
Output is correct |
25 |
Correct |
374 ms |
30180 KB |
Output is correct |
26 |
Correct |
396 ms |
30180 KB |
Output is correct |
27 |
Correct |
397 ms |
30180 KB |
Output is correct |
28 |
Correct |
333 ms |
31112 KB |
Output is correct |
29 |
Correct |
319 ms |
31112 KB |
Output is correct |
30 |
Correct |
429 ms |
31112 KB |
Output is correct |
31 |
Correct |
389 ms |
31112 KB |
Output is correct |
32 |
Correct |
400 ms |
34948 KB |
Output is correct |
33 |
Correct |
435 ms |
38268 KB |
Output is correct |
34 |
Correct |
396 ms |
38308 KB |
Output is correct |
35 |
Correct |
436 ms |
38776 KB |
Output is correct |
36 |
Correct |
370 ms |
38776 KB |
Output is correct |
37 |
Correct |
404 ms |
39348 KB |
Output is correct |
38 |
Correct |
382 ms |
39348 KB |
Output is correct |
39 |
Correct |
462 ms |
39348 KB |
Output is correct |
40 |
Correct |
414 ms |
39348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
29 ms |
13048 KB |
Output is correct |
2 |
Correct |
29 ms |
13048 KB |
Output is correct |
3 |
Correct |
33 ms |
13084 KB |
Output is correct |
4 |
Correct |
29 ms |
13144 KB |
Output is correct |
5 |
Correct |
33 ms |
13400 KB |
Output is correct |
6 |
Correct |
31 ms |
13400 KB |
Output is correct |
7 |
Correct |
29 ms |
13400 KB |
Output is correct |
8 |
Correct |
28 ms |
13400 KB |
Output is correct |
9 |
Correct |
29 ms |
13400 KB |
Output is correct |
10 |
Correct |
27 ms |
13400 KB |
Output is correct |
11 |
Incorrect |
659 ms |
39348 KB |
Output isn't correct |
12 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
29 ms |
13048 KB |
Output is correct |
2 |
Correct |
29 ms |
13048 KB |
Output is correct |
3 |
Correct |
33 ms |
13084 KB |
Output is correct |
4 |
Correct |
29 ms |
13144 KB |
Output is correct |
5 |
Correct |
33 ms |
13400 KB |
Output is correct |
6 |
Correct |
31 ms |
13400 KB |
Output is correct |
7 |
Correct |
29 ms |
13400 KB |
Output is correct |
8 |
Correct |
28 ms |
13400 KB |
Output is correct |
9 |
Correct |
29 ms |
13400 KB |
Output is correct |
10 |
Correct |
27 ms |
13400 KB |
Output is correct |
11 |
Correct |
322 ms |
29008 KB |
Output is correct |
12 |
Correct |
370 ms |
29008 KB |
Output is correct |
13 |
Correct |
349 ms |
29008 KB |
Output is correct |
14 |
Correct |
314 ms |
29008 KB |
Output is correct |
15 |
Correct |
387 ms |
29304 KB |
Output is correct |
16 |
Correct |
389 ms |
29304 KB |
Output is correct |
17 |
Correct |
383 ms |
29304 KB |
Output is correct |
18 |
Correct |
317 ms |
30176 KB |
Output is correct |
19 |
Correct |
291 ms |
30176 KB |
Output is correct |
20 |
Correct |
394 ms |
30176 KB |
Output is correct |
21 |
Correct |
429 ms |
30176 KB |
Output is correct |
22 |
Correct |
477 ms |
30176 KB |
Output is correct |
23 |
Correct |
397 ms |
30176 KB |
Output is correct |
24 |
Correct |
371 ms |
30176 KB |
Output is correct |
25 |
Correct |
374 ms |
30180 KB |
Output is correct |
26 |
Correct |
396 ms |
30180 KB |
Output is correct |
27 |
Correct |
397 ms |
30180 KB |
Output is correct |
28 |
Correct |
333 ms |
31112 KB |
Output is correct |
29 |
Correct |
319 ms |
31112 KB |
Output is correct |
30 |
Correct |
429 ms |
31112 KB |
Output is correct |
31 |
Correct |
389 ms |
31112 KB |
Output is correct |
32 |
Correct |
400 ms |
34948 KB |
Output is correct |
33 |
Correct |
435 ms |
38268 KB |
Output is correct |
34 |
Correct |
396 ms |
38308 KB |
Output is correct |
35 |
Correct |
436 ms |
38776 KB |
Output is correct |
36 |
Correct |
370 ms |
38776 KB |
Output is correct |
37 |
Correct |
404 ms |
39348 KB |
Output is correct |
38 |
Correct |
382 ms |
39348 KB |
Output is correct |
39 |
Correct |
462 ms |
39348 KB |
Output is correct |
40 |
Correct |
414 ms |
39348 KB |
Output is correct |
41 |
Incorrect |
659 ms |
39348 KB |
Output isn't correct |
42 |
Halted |
0 ms |
0 KB |
- |