# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
80265 | 2018-10-19T17:03:59 Z | Bodo171 | Snake Escaping (JOI18_snake_escaping) | C++14 | 1067 ms | 61848 KB |
#include <cstdio> using namespace std; const int nmax=(1<<20); char s[20],str[nmax]; char t; char pc[nmax]; int sub[nmax],supra[nmax]; int l,q,i,j,m0,m1,mq,ans,cnt; char mn; bool brk; int main() { //freopen("data.in","r",stdin); scanf("%d%d",&l,&q); scanf("%s",&str); for(i=0;i<(1<<l);i++) { if(i!=0) pc[i]=pc[(i&(i-1))]+1; sub[i]=supra[i]=str[i]=str[i]-'0'; } for(i=0;i<l;i++) for(j=0;j<(1<<l);j++) if(((1<<i)&j)) sub[j]+=sub[(j^(1<<i))]; else supra[j]+=supra[(j^(1<<i))]; for(cnt=1;cnt<=q;cnt++) { scanf("%s",&s); m0=m1=mq=0; for(j=l-1;j>=0;j--) { t=s[l-1-j]; if(t=='0') m0|=(1<<j); else if(t=='1') m1|=(1<<j); else mq|=(1<<j); } mn=pc[m0]; if(pc[m1]<mn) mn=pc[m1]; if(pc[mq]<mn) mn=pc[mq]; ans=0;brk=0; if(mn==pc[m0]) { ans=supra[m1]; i=m0; while(i!=0) { if((pc[i]&1)) ans-=supra[(i|m1)]; else ans+=supra[(i|m1)]; i=((i-1)&m0); } } else { if(mn==pc[m1]) { i=m1; while(!brk) { if(i==0) brk=1; if(((pc[m1]-pc[i])&1)) ans-=sub[(i|mq)]; else ans+=sub[(i|mq)]; i=((i-1)&m1); } } else { i=mq; while(!brk) { ans+=str[(m1|i)]; if(i==0) brk=1; i=((i-1)&mq); } } } printf("%d\n",ans); } return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 348 KB | Output is correct |
2 | Correct | 2 ms | 392 KB | Output is correct |
3 | Correct | 2 ms | 484 KB | Output is correct |
4 | Correct | 2 ms | 508 KB | Output is correct |
5 | Correct | 2 ms | 580 KB | Output is correct |
6 | Correct | 2 ms | 636 KB | Output is correct |
7 | Correct | 2 ms | 692 KB | Output is correct |
8 | Correct | 2 ms | 720 KB | Output is correct |
9 | Correct | 2 ms | 732 KB | Output is correct |
10 | Correct | 2 ms | 744 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 348 KB | Output is correct |
2 | Correct | 2 ms | 392 KB | Output is correct |
3 | Correct | 2 ms | 484 KB | Output is correct |
4 | Correct | 2 ms | 508 KB | Output is correct |
5 | Correct | 2 ms | 580 KB | Output is correct |
6 | Correct | 2 ms | 636 KB | Output is correct |
7 | Correct | 2 ms | 692 KB | Output is correct |
8 | Correct | 2 ms | 720 KB | Output is correct |
9 | Correct | 2 ms | 732 KB | Output is correct |
10 | Correct | 2 ms | 744 KB | Output is correct |
11 | Correct | 270 ms | 7428 KB | Output is correct |
12 | Correct | 302 ms | 7428 KB | Output is correct |
13 | Correct | 324 ms | 10516 KB | Output is correct |
14 | Correct | 348 ms | 10632 KB | Output is correct |
15 | Correct | 341 ms | 11580 KB | Output is correct |
16 | Correct | 350 ms | 11580 KB | Output is correct |
17 | Correct | 434 ms | 12624 KB | Output is correct |
18 | Correct | 265 ms | 14324 KB | Output is correct |
19 | Correct | 267 ms | 14324 KB | Output is correct |
20 | Correct | 276 ms | 14324 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 348 KB | Output is correct |
2 | Correct | 2 ms | 392 KB | Output is correct |
3 | Correct | 2 ms | 484 KB | Output is correct |
4 | Correct | 2 ms | 508 KB | Output is correct |
5 | Correct | 2 ms | 580 KB | Output is correct |
6 | Correct | 2 ms | 636 KB | Output is correct |
7 | Correct | 2 ms | 692 KB | Output is correct |
8 | Correct | 2 ms | 720 KB | Output is correct |
9 | Correct | 2 ms | 732 KB | Output is correct |
10 | Correct | 2 ms | 744 KB | Output is correct |
11 | Correct | 270 ms | 7428 KB | Output is correct |
12 | Correct | 302 ms | 7428 KB | Output is correct |
13 | Correct | 324 ms | 10516 KB | Output is correct |
14 | Correct | 348 ms | 10632 KB | Output is correct |
15 | Correct | 341 ms | 11580 KB | Output is correct |
16 | Correct | 350 ms | 11580 KB | Output is correct |
17 | Correct | 434 ms | 12624 KB | Output is correct |
18 | Correct | 265 ms | 14324 KB | Output is correct |
19 | Correct | 267 ms | 14324 KB | Output is correct |
20 | Correct | 276 ms | 14324 KB | Output is correct |
21 | Correct | 348 ms | 15328 KB | Output is correct |
22 | Correct | 345 ms | 17356 KB | Output is correct |
23 | Correct | 380 ms | 17356 KB | Output is correct |
24 | Correct | 419 ms | 17356 KB | Output is correct |
25 | Correct | 360 ms | 19004 KB | Output is correct |
26 | Correct | 439 ms | 19004 KB | Output is correct |
27 | Correct | 390 ms | 19004 KB | Output is correct |
28 | Correct | 256 ms | 20688 KB | Output is correct |
29 | Correct | 369 ms | 20688 KB | Output is correct |
30 | Correct | 344 ms | 20688 KB | Output is correct |
31 | Correct | 370 ms | 20688 KB | Output is correct |
32 | Correct | 381 ms | 20688 KB | Output is correct |
33 | Correct | 359 ms | 20944 KB | Output is correct |
34 | Correct | 395 ms | 20984 KB | Output is correct |
35 | Correct | 390 ms | 21372 KB | Output is correct |
36 | Correct | 250 ms | 21372 KB | Output is correct |
37 | Correct | 329 ms | 23344 KB | Output is correct |
38 | Correct | 348 ms | 23344 KB | Output is correct |
39 | Correct | 370 ms | 23344 KB | Output is correct |
40 | Correct | 421 ms | 23344 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 348 KB | Output is correct |
2 | Correct | 2 ms | 392 KB | Output is correct |
3 | Correct | 2 ms | 484 KB | Output is correct |
4 | Correct | 2 ms | 508 KB | Output is correct |
5 | Correct | 2 ms | 580 KB | Output is correct |
6 | Correct | 2 ms | 636 KB | Output is correct |
7 | Correct | 2 ms | 692 KB | Output is correct |
8 | Correct | 2 ms | 720 KB | Output is correct |
9 | Correct | 2 ms | 732 KB | Output is correct |
10 | Correct | 2 ms | 744 KB | Output is correct |
11 | Correct | 101 ms | 29800 KB | Output is correct |
12 | Correct | 71 ms | 29800 KB | Output is correct |
13 | Correct | 78 ms | 29800 KB | Output is correct |
14 | Correct | 84 ms | 29800 KB | Output is correct |
15 | Correct | 66 ms | 29816 KB | Output is correct |
16 | Correct | 92 ms | 30584 KB | Output is correct |
17 | Correct | 84 ms | 30584 KB | Output is correct |
18 | Correct | 58 ms | 30584 KB | Output is correct |
19 | Correct | 87 ms | 30584 KB | Output is correct |
20 | Correct | 92 ms | 30584 KB | Output is correct |
21 | Correct | 86 ms | 30584 KB | Output is correct |
22 | Correct | 83 ms | 30584 KB | Output is correct |
23 | Correct | 73 ms | 30584 KB | Output is correct |
24 | Correct | 90 ms | 30584 KB | Output is correct |
25 | Correct | 88 ms | 30584 KB | Output is correct |
26 | Correct | 61 ms | 30584 KB | Output is correct |
27 | Correct | 71 ms | 30584 KB | Output is correct |
28 | Correct | 76 ms | 30584 KB | Output is correct |
29 | Correct | 73 ms | 30584 KB | Output is correct |
30 | Correct | 79 ms | 30584 KB | Output is correct |
31 | Correct | 67 ms | 30584 KB | Output is correct |
32 | Correct | 92 ms | 30584 KB | Output is correct |
33 | Correct | 81 ms | 30584 KB | Output is correct |
34 | Correct | 58 ms | 30584 KB | Output is correct |
35 | Correct | 89 ms | 30584 KB | Output is correct |
36 | Correct | 79 ms | 30584 KB | Output is correct |
37 | Correct | 75 ms | 30584 KB | Output is correct |
38 | Correct | 79 ms | 30584 KB | Output is correct |
39 | Correct | 78 ms | 30584 KB | Output is correct |
40 | Correct | 80 ms | 30584 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 348 KB | Output is correct |
2 | Correct | 2 ms | 392 KB | Output is correct |
3 | Correct | 2 ms | 484 KB | Output is correct |
4 | Correct | 2 ms | 508 KB | Output is correct |
5 | Correct | 2 ms | 580 KB | Output is correct |
6 | Correct | 2 ms | 636 KB | Output is correct |
7 | Correct | 2 ms | 692 KB | Output is correct |
8 | Correct | 2 ms | 720 KB | Output is correct |
9 | Correct | 2 ms | 732 KB | Output is correct |
10 | Correct | 2 ms | 744 KB | Output is correct |
11 | Correct | 270 ms | 7428 KB | Output is correct |
12 | Correct | 302 ms | 7428 KB | Output is correct |
13 | Correct | 324 ms | 10516 KB | Output is correct |
14 | Correct | 348 ms | 10632 KB | Output is correct |
15 | Correct | 341 ms | 11580 KB | Output is correct |
16 | Correct | 350 ms | 11580 KB | Output is correct |
17 | Correct | 434 ms | 12624 KB | Output is correct |
18 | Correct | 265 ms | 14324 KB | Output is correct |
19 | Correct | 267 ms | 14324 KB | Output is correct |
20 | Correct | 276 ms | 14324 KB | Output is correct |
21 | Correct | 348 ms | 15328 KB | Output is correct |
22 | Correct | 345 ms | 17356 KB | Output is correct |
23 | Correct | 380 ms | 17356 KB | Output is correct |
24 | Correct | 419 ms | 17356 KB | Output is correct |
25 | Correct | 360 ms | 19004 KB | Output is correct |
26 | Correct | 439 ms | 19004 KB | Output is correct |
27 | Correct | 390 ms | 19004 KB | Output is correct |
28 | Correct | 256 ms | 20688 KB | Output is correct |
29 | Correct | 369 ms | 20688 KB | Output is correct |
30 | Correct | 344 ms | 20688 KB | Output is correct |
31 | Correct | 370 ms | 20688 KB | Output is correct |
32 | Correct | 381 ms | 20688 KB | Output is correct |
33 | Correct | 359 ms | 20944 KB | Output is correct |
34 | Correct | 395 ms | 20984 KB | Output is correct |
35 | Correct | 390 ms | 21372 KB | Output is correct |
36 | Correct | 250 ms | 21372 KB | Output is correct |
37 | Correct | 329 ms | 23344 KB | Output is correct |
38 | Correct | 348 ms | 23344 KB | Output is correct |
39 | Correct | 370 ms | 23344 KB | Output is correct |
40 | Correct | 421 ms | 23344 KB | Output is correct |
41 | Correct | 101 ms | 29800 KB | Output is correct |
42 | Correct | 71 ms | 29800 KB | Output is correct |
43 | Correct | 78 ms | 29800 KB | Output is correct |
44 | Correct | 84 ms | 29800 KB | Output is correct |
45 | Correct | 66 ms | 29816 KB | Output is correct |
46 | Correct | 92 ms | 30584 KB | Output is correct |
47 | Correct | 84 ms | 30584 KB | Output is correct |
48 | Correct | 58 ms | 30584 KB | Output is correct |
49 | Correct | 87 ms | 30584 KB | Output is correct |
50 | Correct | 92 ms | 30584 KB | Output is correct |
51 | Correct | 86 ms | 30584 KB | Output is correct |
52 | Correct | 83 ms | 30584 KB | Output is correct |
53 | Correct | 73 ms | 30584 KB | Output is correct |
54 | Correct | 90 ms | 30584 KB | Output is correct |
55 | Correct | 88 ms | 30584 KB | Output is correct |
56 | Correct | 61 ms | 30584 KB | Output is correct |
57 | Correct | 71 ms | 30584 KB | Output is correct |
58 | Correct | 76 ms | 30584 KB | Output is correct |
59 | Correct | 73 ms | 30584 KB | Output is correct |
60 | Correct | 79 ms | 30584 KB | Output is correct |
61 | Correct | 67 ms | 30584 KB | Output is correct |
62 | Correct | 92 ms | 30584 KB | Output is correct |
63 | Correct | 81 ms | 30584 KB | Output is correct |
64 | Correct | 58 ms | 30584 KB | Output is correct |
65 | Correct | 89 ms | 30584 KB | Output is correct |
66 | Correct | 79 ms | 30584 KB | Output is correct |
67 | Correct | 75 ms | 30584 KB | Output is correct |
68 | Correct | 79 ms | 30584 KB | Output is correct |
69 | Correct | 78 ms | 30584 KB | Output is correct |
70 | Correct | 80 ms | 30584 KB | Output is correct |
71 | Correct | 531 ms | 35288 KB | Output is correct |
72 | Correct | 544 ms | 35288 KB | Output is correct |
73 | Correct | 605 ms | 35288 KB | Output is correct |
74 | Correct | 796 ms | 35288 KB | Output is correct |
75 | Correct | 510 ms | 37680 KB | Output is correct |
76 | Correct | 790 ms | 37680 KB | Output is correct |
77 | Correct | 721 ms | 37680 KB | Output is correct |
78 | Correct | 346 ms | 39704 KB | Output is correct |
79 | Correct | 449 ms | 39704 KB | Output is correct |
80 | Correct | 543 ms | 39704 KB | Output is correct |
81 | Correct | 722 ms | 39704 KB | Output is correct |
82 | Correct | 678 ms | 39704 KB | Output is correct |
83 | Correct | 541 ms | 39704 KB | Output is correct |
84 | Correct | 814 ms | 39704 KB | Output is correct |
85 | Correct | 886 ms | 39704 KB | Output is correct |
86 | Correct | 357 ms | 39704 KB | Output is correct |
87 | Correct | 544 ms | 40128 KB | Output is correct |
88 | Correct | 509 ms | 40128 KB | Output is correct |
89 | Correct | 592 ms | 40128 KB | Output is correct |
90 | Correct | 644 ms | 40128 KB | Output is correct |
91 | Correct | 526 ms | 40128 KB | Output is correct |
92 | Correct | 1067 ms | 40128 KB | Output is correct |
93 | Correct | 888 ms | 40128 KB | Output is correct |
94 | Correct | 352 ms | 40128 KB | Output is correct |
95 | Correct | 788 ms | 40128 KB | Output is correct |
96 | Correct | 735 ms | 40136 KB | Output is correct |
97 | Correct | 769 ms | 40172 KB | Output is correct |
98 | Correct | 705 ms | 40180 KB | Output is correct |
99 | Correct | 646 ms | 61636 KB | Output is correct |
100 | Correct | 712 ms | 61848 KB | Output is correct |