# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
66952 | 2018-08-12T20:44:51 Z | hamzqq9 | Snake Escaping (JOI18_snake_escaping) | C++14 | 2000 ms | 54592 KB |
#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 8 #define R 12 using namespace std; int n,q,l; int cnt[531441],ans[pw(20)+5]; int po3[20],po2[25],pos[531441]; char val[pw(20)+5],s[pw(20)+5]; bool oops[531441],inc[6561][256]; int Right[pw(20)+5]; short Left[pw(20)+5]; void do_dp(int value) { for(int i=0;i<531441;i++) { if(oops[i]) cnt[i]=val[value*po2[R]+pos[i]]; else cnt[i]=cnt[i-po3[pos[i]]]+cnt[i-2*po3[pos[i]]]; } } void pre_cal() { oops[0]=oops[1]=true; pos[1]=1; for(int i=3;i<531441;i++) { if(i%3==2) pos[i]=0; else { int val=i/3; if(oops[val]) { oops[i]=true; pos[i]=pos[val]*2+i%3; } else { pos[i]=pos[val]+1; } } } inc[0][0]=true; for(int i=0;i<6561;i++) { for(int j=0;j<256;j++) { if(i%3==2 || i%3==j%2) inc[i][j]=inc[i/3][j/2]; } } } 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]=po2[0]=1; for(int i=1;i<=15;i++) po3[i]=po3[i-1]*3; for(int i=1;i<=20;i++) po2[i]=po2[i-1]*2; scanf("%d %d",&l,&q); n=po2[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[i]=get_value(L,19); Left[i]=get_value(0,L-1); } pre_cal(); for(int i=0;i<po2[L];i++) { do_dp(i); for(int j=1;j<=q;j++) { if(inc[Left[j]][i]) { ans[j]+=cnt[Right[j]]; } } } for(int i=1;i<=q;i++) printf("%d\n",ans[i]); }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 334 ms | 6264 KB | Output is correct |
2 | Correct | 337 ms | 6432 KB | Output is correct |
3 | Correct | 361 ms | 6432 KB | Output is correct |
4 | Correct | 301 ms | 6500 KB | Output is correct |
5 | Correct | 292 ms | 6500 KB | Output is correct |
6 | Correct | 311 ms | 6500 KB | Output is correct |
7 | Correct | 317 ms | 6524 KB | Output is correct |
8 | Correct | 311 ms | 6524 KB | Output is correct |
9 | Correct | 331 ms | 6524 KB | Output is correct |
10 | Correct | 394 ms | 6560 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 334 ms | 6264 KB | Output is correct |
2 | Correct | 337 ms | 6432 KB | Output is correct |
3 | Correct | 361 ms | 6432 KB | Output is correct |
4 | Correct | 301 ms | 6500 KB | Output is correct |
5 | Correct | 292 ms | 6500 KB | Output is correct |
6 | Correct | 311 ms | 6500 KB | Output is correct |
7 | Correct | 317 ms | 6524 KB | Output is correct |
8 | Correct | 311 ms | 6524 KB | Output is correct |
9 | Correct | 331 ms | 6524 KB | Output is correct |
10 | Correct | 394 ms | 6560 KB | Output is correct |
11 | Correct | 889 ms | 20464 KB | Output is correct |
12 | Correct | 933 ms | 20464 KB | Output is correct |
13 | Correct | 951 ms | 20464 KB | Output is correct |
14 | Correct | 1042 ms | 20464 KB | Output is correct |
15 | Correct | 878 ms | 20660 KB | Output is correct |
16 | Correct | 831 ms | 20660 KB | Output is correct |
17 | Correct | 879 ms | 20660 KB | Output is correct |
18 | Correct | 895 ms | 21572 KB | Output is correct |
19 | Correct | 859 ms | 21572 KB | Output is correct |
20 | Correct | 864 ms | 21572 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 334 ms | 6264 KB | Output is correct |
2 | Correct | 337 ms | 6432 KB | Output is correct |
3 | Correct | 361 ms | 6432 KB | Output is correct |
4 | Correct | 301 ms | 6500 KB | Output is correct |
5 | Correct | 292 ms | 6500 KB | Output is correct |
6 | Correct | 311 ms | 6500 KB | Output is correct |
7 | Correct | 317 ms | 6524 KB | Output is correct |
8 | Correct | 311 ms | 6524 KB | Output is correct |
9 | Correct | 331 ms | 6524 KB | Output is correct |
10 | Correct | 394 ms | 6560 KB | Output is correct |
11 | Correct | 889 ms | 20464 KB | Output is correct |
12 | Correct | 933 ms | 20464 KB | Output is correct |
13 | Correct | 951 ms | 20464 KB | Output is correct |
14 | Correct | 1042 ms | 20464 KB | Output is correct |
15 | Correct | 878 ms | 20660 KB | Output is correct |
16 | Correct | 831 ms | 20660 KB | Output is correct |
17 | Correct | 879 ms | 20660 KB | Output is correct |
18 | Correct | 895 ms | 21572 KB | Output is correct |
19 | Correct | 859 ms | 21572 KB | Output is correct |
20 | Correct | 864 ms | 21572 KB | Output is correct |
21 | Correct | 1022 ms | 21572 KB | Output is correct |
22 | Correct | 926 ms | 24340 KB | Output is correct |
23 | Correct | 1108 ms | 24340 KB | Output is correct |
24 | Correct | 880 ms | 24340 KB | Output is correct |
25 | Correct | 945 ms | 25276 KB | Output is correct |
26 | Correct | 969 ms | 25276 KB | Output is correct |
27 | Correct | 847 ms | 25276 KB | Output is correct |
28 | Correct | 867 ms | 26344 KB | Output is correct |
29 | Correct | 782 ms | 26344 KB | Output is correct |
30 | Correct | 871 ms | 26344 KB | Output is correct |
31 | Correct | 955 ms | 26344 KB | Output is correct |
32 | Correct | 892 ms | 29544 KB | Output is correct |
33 | Correct | 854 ms | 40304 KB | Output is correct |
34 | Correct | 909 ms | 40512 KB | Output is correct |
35 | Correct | 987 ms | 40920 KB | Output is correct |
36 | Correct | 800 ms | 40920 KB | Output is correct |
37 | Correct | 864 ms | 41544 KB | Output is correct |
38 | Correct | 803 ms | 41544 KB | Output is correct |
39 | Correct | 961 ms | 41544 KB | Output is correct |
40 | Correct | 838 ms | 41544 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 334 ms | 6264 KB | Output is correct |
2 | Correct | 337 ms | 6432 KB | Output is correct |
3 | Correct | 361 ms | 6432 KB | Output is correct |
4 | Correct | 301 ms | 6500 KB | Output is correct |
5 | Correct | 292 ms | 6500 KB | Output is correct |
6 | Correct | 311 ms | 6500 KB | Output is correct |
7 | Correct | 317 ms | 6524 KB | Output is correct |
8 | Correct | 311 ms | 6524 KB | Output is correct |
9 | Correct | 331 ms | 6524 KB | Output is correct |
10 | Correct | 394 ms | 6560 KB | Output is correct |
11 | Correct | 396 ms | 41544 KB | Output is correct |
12 | Correct | 436 ms | 41544 KB | Output is correct |
13 | Correct | 441 ms | 41544 KB | Output is correct |
14 | Correct | 440 ms | 41544 KB | Output is correct |
15 | Correct | 449 ms | 41544 KB | Output is correct |
16 | Correct | 487 ms | 41544 KB | Output is correct |
17 | Correct | 425 ms | 41544 KB | Output is correct |
18 | Correct | 355 ms | 41544 KB | Output is correct |
19 | Correct | 371 ms | 41544 KB | Output is correct |
20 | Correct | 546 ms | 41544 KB | Output is correct |
21 | Correct | 469 ms | 41544 KB | Output is correct |
22 | Correct | 506 ms | 41544 KB | Output is correct |
23 | Correct | 456 ms | 41544 KB | Output is correct |
24 | Correct | 510 ms | 41544 KB | Output is correct |
25 | Correct | 430 ms | 41544 KB | Output is correct |
26 | Correct | 408 ms | 41544 KB | Output is correct |
27 | Correct | 408 ms | 41544 KB | Output is correct |
28 | Correct | 357 ms | 41544 KB | Output is correct |
29 | Correct | 443 ms | 41544 KB | Output is correct |
30 | Correct | 415 ms | 41544 KB | Output is correct |
31 | Correct | 407 ms | 41544 KB | Output is correct |
32 | Correct | 482 ms | 41544 KB | Output is correct |
33 | Correct | 462 ms | 41544 KB | Output is correct |
34 | Correct | 376 ms | 41544 KB | Output is correct |
35 | Correct | 469 ms | 41544 KB | Output is correct |
36 | Correct | 441 ms | 41544 KB | Output is correct |
37 | Correct | 480 ms | 41544 KB | Output is correct |
38 | Correct | 499 ms | 41544 KB | Output is correct |
39 | Correct | 424 ms | 41544 KB | Output is correct |
40 | Correct | 424 ms | 41544 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 334 ms | 6264 KB | Output is correct |
2 | Correct | 337 ms | 6432 KB | Output is correct |
3 | Correct | 361 ms | 6432 KB | Output is correct |
4 | Correct | 301 ms | 6500 KB | Output is correct |
5 | Correct | 292 ms | 6500 KB | Output is correct |
6 | Correct | 311 ms | 6500 KB | Output is correct |
7 | Correct | 317 ms | 6524 KB | Output is correct |
8 | Correct | 311 ms | 6524 KB | Output is correct |
9 | Correct | 331 ms | 6524 KB | Output is correct |
10 | Correct | 394 ms | 6560 KB | Output is correct |
11 | Correct | 889 ms | 20464 KB | Output is correct |
12 | Correct | 933 ms | 20464 KB | Output is correct |
13 | Correct | 951 ms | 20464 KB | Output is correct |
14 | Correct | 1042 ms | 20464 KB | Output is correct |
15 | Correct | 878 ms | 20660 KB | Output is correct |
16 | Correct | 831 ms | 20660 KB | Output is correct |
17 | Correct | 879 ms | 20660 KB | Output is correct |
18 | Correct | 895 ms | 21572 KB | Output is correct |
19 | Correct | 859 ms | 21572 KB | Output is correct |
20 | Correct | 864 ms | 21572 KB | Output is correct |
21 | Correct | 1022 ms | 21572 KB | Output is correct |
22 | Correct | 926 ms | 24340 KB | Output is correct |
23 | Correct | 1108 ms | 24340 KB | Output is correct |
24 | Correct | 880 ms | 24340 KB | Output is correct |
25 | Correct | 945 ms | 25276 KB | Output is correct |
26 | Correct | 969 ms | 25276 KB | Output is correct |
27 | Correct | 847 ms | 25276 KB | Output is correct |
28 | Correct | 867 ms | 26344 KB | Output is correct |
29 | Correct | 782 ms | 26344 KB | Output is correct |
30 | Correct | 871 ms | 26344 KB | Output is correct |
31 | Correct | 955 ms | 26344 KB | Output is correct |
32 | Correct | 892 ms | 29544 KB | Output is correct |
33 | Correct | 854 ms | 40304 KB | Output is correct |
34 | Correct | 909 ms | 40512 KB | Output is correct |
35 | Correct | 987 ms | 40920 KB | Output is correct |
36 | Correct | 800 ms | 40920 KB | Output is correct |
37 | Correct | 864 ms | 41544 KB | Output is correct |
38 | Correct | 803 ms | 41544 KB | Output is correct |
39 | Correct | 961 ms | 41544 KB | Output is correct |
40 | Correct | 838 ms | 41544 KB | Output is correct |
41 | Correct | 396 ms | 41544 KB | Output is correct |
42 | Correct | 436 ms | 41544 KB | Output is correct |
43 | Correct | 441 ms | 41544 KB | Output is correct |
44 | Correct | 440 ms | 41544 KB | Output is correct |
45 | Correct | 449 ms | 41544 KB | Output is correct |
46 | Correct | 487 ms | 41544 KB | Output is correct |
47 | Correct | 425 ms | 41544 KB | Output is correct |
48 | Correct | 355 ms | 41544 KB | Output is correct |
49 | Correct | 371 ms | 41544 KB | Output is correct |
50 | Correct | 546 ms | 41544 KB | Output is correct |
51 | Correct | 469 ms | 41544 KB | Output is correct |
52 | Correct | 506 ms | 41544 KB | Output is correct |
53 | Correct | 456 ms | 41544 KB | Output is correct |
54 | Correct | 510 ms | 41544 KB | Output is correct |
55 | Correct | 430 ms | 41544 KB | Output is correct |
56 | Correct | 408 ms | 41544 KB | Output is correct |
57 | Correct | 408 ms | 41544 KB | Output is correct |
58 | Correct | 357 ms | 41544 KB | Output is correct |
59 | Correct | 443 ms | 41544 KB | Output is correct |
60 | Correct | 415 ms | 41544 KB | Output is correct |
61 | Correct | 407 ms | 41544 KB | Output is correct |
62 | Correct | 482 ms | 41544 KB | Output is correct |
63 | Correct | 462 ms | 41544 KB | Output is correct |
64 | Correct | 376 ms | 41544 KB | Output is correct |
65 | Correct | 469 ms | 41544 KB | Output is correct |
66 | Correct | 441 ms | 41544 KB | Output is correct |
67 | Correct | 480 ms | 41544 KB | Output is correct |
68 | Correct | 499 ms | 41544 KB | Output is correct |
69 | Correct | 424 ms | 41544 KB | Output is correct |
70 | Correct | 424 ms | 41544 KB | Output is correct |
71 | Correct | 1582 ms | 54512 KB | Output is correct |
72 | Correct | 1865 ms | 54592 KB | Output is correct |
73 | Correct | 1988 ms | 54592 KB | Output is correct |
74 | Execution timed out | 2057 ms | 54592 KB | Time limit exceeded |
75 | Halted | 0 ms | 0 KB | - |