# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
80249 | 2018-10-19T16:43:30 Z | Bodo171 | Snake Escaping (JOI18_snake_escaping) | C++14 | 954 ms | 66560 KB |
#include <cstdio> using namespace std; const int nmax=(1<<20)+5; char s[22],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
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 376 KB | Output is correct |
2 | Correct | 2 ms | 384 KB | Output is correct |
3 | Correct | 2 ms | 432 KB | Output is correct |
4 | Correct | 2 ms | 492 KB | Output is correct |
5 | Correct | 2 ms | 504 KB | Output is correct |
6 | Correct | 2 ms | 516 KB | Output is correct |
7 | Correct | 2 ms | 528 KB | Output is correct |
8 | Correct | 2 ms | 528 KB | Output is correct |
9 | Correct | 2 ms | 552 KB | Output is correct |
10 | Correct | 2 ms | 624 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 376 KB | Output is correct |
2 | Correct | 2 ms | 384 KB | Output is correct |
3 | Correct | 2 ms | 432 KB | Output is correct |
4 | Correct | 2 ms | 492 KB | Output is correct |
5 | Correct | 2 ms | 504 KB | Output is correct |
6 | Correct | 2 ms | 516 KB | Output is correct |
7 | Correct | 2 ms | 528 KB | Output is correct |
8 | Correct | 2 ms | 528 KB | Output is correct |
9 | Correct | 2 ms | 552 KB | Output is correct |
10 | Correct | 2 ms | 624 KB | Output is correct |
11 | Correct | 306 ms | 5920 KB | Output is correct |
12 | Correct | 287 ms | 5920 KB | Output is correct |
13 | Correct | 331 ms | 5920 KB | Output is correct |
14 | Correct | 364 ms | 5920 KB | Output is correct |
15 | Correct | 293 ms | 6320 KB | Output is correct |
16 | Correct | 316 ms | 6320 KB | Output is correct |
17 | Correct | 328 ms | 6320 KB | Output is correct |
18 | Correct | 231 ms | 8088 KB | Output is correct |
19 | Correct | 260 ms | 8088 KB | Output is correct |
20 | Correct | 281 ms | 8088 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 376 KB | Output is correct |
2 | Correct | 2 ms | 384 KB | Output is correct |
3 | Correct | 2 ms | 432 KB | Output is correct |
4 | Correct | 2 ms | 492 KB | Output is correct |
5 | Correct | 2 ms | 504 KB | Output is correct |
6 | Correct | 2 ms | 516 KB | Output is correct |
7 | Correct | 2 ms | 528 KB | Output is correct |
8 | Correct | 2 ms | 528 KB | Output is correct |
9 | Correct | 2 ms | 552 KB | Output is correct |
10 | Correct | 2 ms | 624 KB | Output is correct |
11 | Correct | 306 ms | 5920 KB | Output is correct |
12 | Correct | 287 ms | 5920 KB | Output is correct |
13 | Correct | 331 ms | 5920 KB | Output is correct |
14 | Correct | 364 ms | 5920 KB | Output is correct |
15 | Correct | 293 ms | 6320 KB | Output is correct |
16 | Correct | 316 ms | 6320 KB | Output is correct |
17 | Correct | 328 ms | 6320 KB | Output is correct |
18 | Correct | 231 ms | 8088 KB | Output is correct |
19 | Correct | 260 ms | 8088 KB | Output is correct |
20 | Correct | 281 ms | 8088 KB | Output is correct |
21 | Correct | 390 ms | 8088 KB | Output is correct |
22 | Correct | 331 ms | 8088 KB | Output is correct |
23 | Correct | 394 ms | 8088 KB | Output is correct |
24 | Correct | 396 ms | 8088 KB | Output is correct |
25 | Correct | 341 ms | 8216 KB | Output is correct |
26 | Correct | 406 ms | 8216 KB | Output is correct |
27 | Correct | 388 ms | 8216 KB | Output is correct |
28 | Correct | 263 ms | 9260 KB | Output is correct |
29 | Correct | 311 ms | 9260 KB | Output is correct |
30 | Correct | 341 ms | 9260 KB | Output is correct |
31 | Correct | 368 ms | 9260 KB | Output is correct |
32 | Correct | 386 ms | 9260 KB | Output is correct |
33 | Correct | 348 ms | 9260 KB | Output is correct |
34 | Correct | 444 ms | 9260 KB | Output is correct |
35 | Correct | 485 ms | 9260 KB | Output is correct |
36 | Correct | 257 ms | 9260 KB | Output is correct |
37 | Correct | 377 ms | 9260 KB | Output is correct |
38 | Correct | 323 ms | 9260 KB | Output is correct |
39 | Correct | 370 ms | 9260 KB | Output is correct |
40 | Correct | 399 ms | 9260 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 376 KB | Output is correct |
2 | Correct | 2 ms | 384 KB | Output is correct |
3 | Correct | 2 ms | 432 KB | Output is correct |
4 | Correct | 2 ms | 492 KB | Output is correct |
5 | Correct | 2 ms | 504 KB | Output is correct |
6 | Correct | 2 ms | 516 KB | Output is correct |
7 | Correct | 2 ms | 528 KB | Output is correct |
8 | Correct | 2 ms | 528 KB | Output is correct |
9 | Correct | 2 ms | 552 KB | Output is correct |
10 | Correct | 2 ms | 624 KB | Output is correct |
11 | Correct | 67 ms | 13592 KB | Output is correct |
12 | Correct | 66 ms | 13592 KB | Output is correct |
13 | Correct | 74 ms | 13592 KB | Output is correct |
14 | Correct | 83 ms | 13592 KB | Output is correct |
15 | Correct | 70 ms | 13720 KB | Output is correct |
16 | Correct | 87 ms | 13720 KB | Output is correct |
17 | Correct | 82 ms | 13720 KB | Output is correct |
18 | Correct | 59 ms | 13736 KB | Output is correct |
19 | Correct | 66 ms | 13736 KB | Output is correct |
20 | Correct | 67 ms | 13776 KB | Output is correct |
21 | Correct | 72 ms | 13776 KB | Output is correct |
22 | Correct | 77 ms | 13776 KB | Output is correct |
23 | Correct | 67 ms | 13776 KB | Output is correct |
24 | Correct | 94 ms | 13776 KB | Output is correct |
25 | Correct | 109 ms | 13776 KB | Output is correct |
26 | Correct | 59 ms | 13776 KB | Output is correct |
27 | Correct | 80 ms | 13776 KB | Output is correct |
28 | Correct | 67 ms | 13776 KB | Output is correct |
29 | Correct | 82 ms | 13776 KB | Output is correct |
30 | Correct | 74 ms | 13776 KB | Output is correct |
31 | Correct | 67 ms | 13776 KB | Output is correct |
32 | Correct | 88 ms | 13776 KB | Output is correct |
33 | Correct | 89 ms | 13776 KB | Output is correct |
34 | Correct | 60 ms | 13776 KB | Output is correct |
35 | Correct | 85 ms | 13776 KB | Output is correct |
36 | Correct | 79 ms | 13776 KB | Output is correct |
37 | Correct | 79 ms | 13776 KB | Output is correct |
38 | Correct | 77 ms | 13776 KB | Output is correct |
39 | Correct | 78 ms | 13776 KB | Output is correct |
40 | Correct | 81 ms | 13776 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 376 KB | Output is correct |
2 | Correct | 2 ms | 384 KB | Output is correct |
3 | Correct | 2 ms | 432 KB | Output is correct |
4 | Correct | 2 ms | 492 KB | Output is correct |
5 | Correct | 2 ms | 504 KB | Output is correct |
6 | Correct | 2 ms | 516 KB | Output is correct |
7 | Correct | 2 ms | 528 KB | Output is correct |
8 | Correct | 2 ms | 528 KB | Output is correct |
9 | Correct | 2 ms | 552 KB | Output is correct |
10 | Correct | 2 ms | 624 KB | Output is correct |
11 | Correct | 306 ms | 5920 KB | Output is correct |
12 | Correct | 287 ms | 5920 KB | Output is correct |
13 | Correct | 331 ms | 5920 KB | Output is correct |
14 | Correct | 364 ms | 5920 KB | Output is correct |
15 | Correct | 293 ms | 6320 KB | Output is correct |
16 | Correct | 316 ms | 6320 KB | Output is correct |
17 | Correct | 328 ms | 6320 KB | Output is correct |
18 | Correct | 231 ms | 8088 KB | Output is correct |
19 | Correct | 260 ms | 8088 KB | Output is correct |
20 | Correct | 281 ms | 8088 KB | Output is correct |
21 | Correct | 390 ms | 8088 KB | Output is correct |
22 | Correct | 331 ms | 8088 KB | Output is correct |
23 | Correct | 394 ms | 8088 KB | Output is correct |
24 | Correct | 396 ms | 8088 KB | Output is correct |
25 | Correct | 341 ms | 8216 KB | Output is correct |
26 | Correct | 406 ms | 8216 KB | Output is correct |
27 | Correct | 388 ms | 8216 KB | Output is correct |
28 | Correct | 263 ms | 9260 KB | Output is correct |
29 | Correct | 311 ms | 9260 KB | Output is correct |
30 | Correct | 341 ms | 9260 KB | Output is correct |
31 | Correct | 368 ms | 9260 KB | Output is correct |
32 | Correct | 386 ms | 9260 KB | Output is correct |
33 | Correct | 348 ms | 9260 KB | Output is correct |
34 | Correct | 444 ms | 9260 KB | Output is correct |
35 | Correct | 485 ms | 9260 KB | Output is correct |
36 | Correct | 257 ms | 9260 KB | Output is correct |
37 | Correct | 377 ms | 9260 KB | Output is correct |
38 | Correct | 323 ms | 9260 KB | Output is correct |
39 | Correct | 370 ms | 9260 KB | Output is correct |
40 | Correct | 399 ms | 9260 KB | Output is correct |
41 | Correct | 67 ms | 13592 KB | Output is correct |
42 | Correct | 66 ms | 13592 KB | Output is correct |
43 | Correct | 74 ms | 13592 KB | Output is correct |
44 | Correct | 83 ms | 13592 KB | Output is correct |
45 | Correct | 70 ms | 13720 KB | Output is correct |
46 | Correct | 87 ms | 13720 KB | Output is correct |
47 | Correct | 82 ms | 13720 KB | Output is correct |
48 | Correct | 59 ms | 13736 KB | Output is correct |
49 | Correct | 66 ms | 13736 KB | Output is correct |
50 | Correct | 67 ms | 13776 KB | Output is correct |
51 | Correct | 72 ms | 13776 KB | Output is correct |
52 | Correct | 77 ms | 13776 KB | Output is correct |
53 | Correct | 67 ms | 13776 KB | Output is correct |
54 | Correct | 94 ms | 13776 KB | Output is correct |
55 | Correct | 109 ms | 13776 KB | Output is correct |
56 | Correct | 59 ms | 13776 KB | Output is correct |
57 | Correct | 80 ms | 13776 KB | Output is correct |
58 | Correct | 67 ms | 13776 KB | Output is correct |
59 | Correct | 82 ms | 13776 KB | Output is correct |
60 | Correct | 74 ms | 13776 KB | Output is correct |
61 | Correct | 67 ms | 13776 KB | Output is correct |
62 | Correct | 88 ms | 13776 KB | Output is correct |
63 | Correct | 89 ms | 13776 KB | Output is correct |
64 | Correct | 60 ms | 13776 KB | Output is correct |
65 | Correct | 85 ms | 13776 KB | Output is correct |
66 | Correct | 79 ms | 13776 KB | Output is correct |
67 | Correct | 79 ms | 13776 KB | Output is correct |
68 | Correct | 77 ms | 13776 KB | Output is correct |
69 | Correct | 78 ms | 13776 KB | Output is correct |
70 | Correct | 81 ms | 13776 KB | Output is correct |
71 | Correct | 521 ms | 18260 KB | Output is correct |
72 | Correct | 567 ms | 18548 KB | Output is correct |
73 | Correct | 672 ms | 18548 KB | Output is correct |
74 | Correct | 818 ms | 18548 KB | Output is correct |
75 | Correct | 514 ms | 19512 KB | Output is correct |
76 | Correct | 845 ms | 19512 KB | Output is correct |
77 | Correct | 954 ms | 19512 KB | Output is correct |
78 | Correct | 381 ms | 21288 KB | Output is correct |
79 | Correct | 475 ms | 21288 KB | Output is correct |
80 | Correct | 577 ms | 21288 KB | Output is correct |
81 | Correct | 694 ms | 21288 KB | Output is correct |
82 | Correct | 801 ms | 21288 KB | Output is correct |
83 | Correct | 549 ms | 38456 KB | Output is correct |
84 | Correct | 936 ms | 38980 KB | Output is correct |
85 | Correct | 879 ms | 39300 KB | Output is correct |
86 | Correct | 360 ms | 39300 KB | Output is correct |
87 | Correct | 579 ms | 54916 KB | Output is correct |
88 | Correct | 523 ms | 58732 KB | Output is correct |
89 | Runtime error | 678 ms | 66560 KB | Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience. |
90 | Halted | 0 ms | 0 KB | - |