# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
80259 | 2018-10-19T17:01:26 Z | Bodo171 | Snake Escaping (JOI18_snake_escaping) | C++14 | 995 ms | 66560 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
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 376 KB | Output is correct |
2 | Correct | 3 ms | 512 KB | Output is correct |
3 | Correct | 2 ms | 512 KB | Output is correct |
4 | Correct | 3 ms | 512 KB | Output is correct |
5 | Correct | 2 ms | 512 KB | Output is correct |
6 | Correct | 3 ms | 532 KB | Output is correct |
7 | Correct | 3 ms | 720 KB | Output is correct |
8 | Correct | 2 ms | 720 KB | Output is correct |
9 | Correct | 2 ms | 720 KB | Output is correct |
10 | Correct | 2 ms | 720 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 376 KB | Output is correct |
2 | Correct | 3 ms | 512 KB | Output is correct |
3 | Correct | 2 ms | 512 KB | Output is correct |
4 | Correct | 3 ms | 512 KB | Output is correct |
5 | Correct | 2 ms | 512 KB | Output is correct |
6 | Correct | 3 ms | 532 KB | Output is correct |
7 | Correct | 3 ms | 720 KB | Output is correct |
8 | Correct | 2 ms | 720 KB | Output is correct |
9 | Correct | 2 ms | 720 KB | Output is correct |
10 | Correct | 2 ms | 720 KB | Output is correct |
11 | Correct | 298 ms | 5460 KB | Output is correct |
12 | Correct | 291 ms | 5460 KB | Output is correct |
13 | Correct | 315 ms | 5460 KB | Output is correct |
14 | Correct | 320 ms | 5460 KB | Output is correct |
15 | Correct | 339 ms | 5788 KB | Output is correct |
16 | Correct | 317 ms | 5788 KB | Output is correct |
17 | Correct | 332 ms | 5788 KB | Output is correct |
18 | Correct | 229 ms | 6796 KB | Output is correct |
19 | Correct | 287 ms | 6796 KB | Output is correct |
20 | Correct | 277 ms | 6796 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 376 KB | Output is correct |
2 | Correct | 3 ms | 512 KB | Output is correct |
3 | Correct | 2 ms | 512 KB | Output is correct |
4 | Correct | 3 ms | 512 KB | Output is correct |
5 | Correct | 2 ms | 512 KB | Output is correct |
6 | Correct | 3 ms | 532 KB | Output is correct |
7 | Correct | 3 ms | 720 KB | Output is correct |
8 | Correct | 2 ms | 720 KB | Output is correct |
9 | Correct | 2 ms | 720 KB | Output is correct |
10 | Correct | 2 ms | 720 KB | Output is correct |
11 | Correct | 298 ms | 5460 KB | Output is correct |
12 | Correct | 291 ms | 5460 KB | Output is correct |
13 | Correct | 315 ms | 5460 KB | Output is correct |
14 | Correct | 320 ms | 5460 KB | Output is correct |
15 | Correct | 339 ms | 5788 KB | Output is correct |
16 | Correct | 317 ms | 5788 KB | Output is correct |
17 | Correct | 332 ms | 5788 KB | Output is correct |
18 | Correct | 229 ms | 6796 KB | Output is correct |
19 | Correct | 287 ms | 6796 KB | Output is correct |
20 | Correct | 277 ms | 6796 KB | Output is correct |
21 | Correct | 330 ms | 6796 KB | Output is correct |
22 | Correct | 353 ms | 6796 KB | Output is correct |
23 | Correct | 379 ms | 6796 KB | Output is correct |
24 | Correct | 402 ms | 6796 KB | Output is correct |
25 | Correct | 372 ms | 6892 KB | Output is correct |
26 | Correct | 417 ms | 6892 KB | Output is correct |
27 | Correct | 400 ms | 6892 KB | Output is correct |
28 | Correct | 256 ms | 7880 KB | Output is correct |
29 | Correct | 331 ms | 7880 KB | Output is correct |
30 | Correct | 371 ms | 7880 KB | Output is correct |
31 | Correct | 388 ms | 7880 KB | Output is correct |
32 | Correct | 437 ms | 7880 KB | Output is correct |
33 | Correct | 373 ms | 7880 KB | Output is correct |
34 | Correct | 432 ms | 7880 KB | Output is correct |
35 | Correct | 423 ms | 7880 KB | Output is correct |
36 | Correct | 255 ms | 7880 KB | Output is correct |
37 | Correct | 336 ms | 7880 KB | Output is correct |
38 | Correct | 350 ms | 7880 KB | Output is correct |
39 | Correct | 385 ms | 7880 KB | Output is correct |
40 | Correct | 425 ms | 7880 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 376 KB | Output is correct |
2 | Correct | 3 ms | 512 KB | Output is correct |
3 | Correct | 2 ms | 512 KB | Output is correct |
4 | Correct | 3 ms | 512 KB | Output is correct |
5 | Correct | 2 ms | 512 KB | Output is correct |
6 | Correct | 3 ms | 532 KB | Output is correct |
7 | Correct | 3 ms | 720 KB | Output is correct |
8 | Correct | 2 ms | 720 KB | Output is correct |
9 | Correct | 2 ms | 720 KB | Output is correct |
10 | Correct | 2 ms | 720 KB | Output is correct |
11 | Correct | 72 ms | 12228 KB | Output is correct |
12 | Correct | 77 ms | 12248 KB | Output is correct |
13 | Correct | 77 ms | 12248 KB | Output is correct |
14 | Correct | 134 ms | 12248 KB | Output is correct |
15 | Correct | 72 ms | 12356 KB | Output is correct |
16 | Correct | 90 ms | 12356 KB | Output is correct |
17 | Correct | 125 ms | 12356 KB | Output is correct |
18 | Correct | 62 ms | 12372 KB | Output is correct |
19 | Correct | 67 ms | 12372 KB | Output is correct |
20 | Correct | 71 ms | 12372 KB | Output is correct |
21 | Correct | 77 ms | 12372 KB | Output is correct |
22 | Correct | 86 ms | 12372 KB | Output is correct |
23 | Correct | 87 ms | 12372 KB | Output is correct |
24 | Correct | 93 ms | 12372 KB | Output is correct |
25 | Correct | 88 ms | 12372 KB | Output is correct |
26 | Correct | 61 ms | 12372 KB | Output is correct |
27 | Correct | 78 ms | 12372 KB | Output is correct |
28 | Correct | 72 ms | 12372 KB | Output is correct |
29 | Correct | 77 ms | 12372 KB | Output is correct |
30 | Correct | 76 ms | 12372 KB | Output is correct |
31 | Correct | 70 ms | 12372 KB | Output is correct |
32 | Correct | 87 ms | 12372 KB | Output is correct |
33 | Correct | 92 ms | 12372 KB | Output is correct |
34 | Correct | 59 ms | 12372 KB | Output is correct |
35 | Correct | 89 ms | 12372 KB | Output is correct |
36 | Correct | 82 ms | 12372 KB | Output is correct |
37 | Correct | 83 ms | 12372 KB | Output is correct |
38 | Correct | 81 ms | 12372 KB | Output is correct |
39 | Correct | 92 ms | 12372 KB | Output is correct |
40 | Correct | 92 ms | 12372 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 376 KB | Output is correct |
2 | Correct | 3 ms | 512 KB | Output is correct |
3 | Correct | 2 ms | 512 KB | Output is correct |
4 | Correct | 3 ms | 512 KB | Output is correct |
5 | Correct | 2 ms | 512 KB | Output is correct |
6 | Correct | 3 ms | 532 KB | Output is correct |
7 | Correct | 3 ms | 720 KB | Output is correct |
8 | Correct | 2 ms | 720 KB | Output is correct |
9 | Correct | 2 ms | 720 KB | Output is correct |
10 | Correct | 2 ms | 720 KB | Output is correct |
11 | Correct | 298 ms | 5460 KB | Output is correct |
12 | Correct | 291 ms | 5460 KB | Output is correct |
13 | Correct | 315 ms | 5460 KB | Output is correct |
14 | Correct | 320 ms | 5460 KB | Output is correct |
15 | Correct | 339 ms | 5788 KB | Output is correct |
16 | Correct | 317 ms | 5788 KB | Output is correct |
17 | Correct | 332 ms | 5788 KB | Output is correct |
18 | Correct | 229 ms | 6796 KB | Output is correct |
19 | Correct | 287 ms | 6796 KB | Output is correct |
20 | Correct | 277 ms | 6796 KB | Output is correct |
21 | Correct | 330 ms | 6796 KB | Output is correct |
22 | Correct | 353 ms | 6796 KB | Output is correct |
23 | Correct | 379 ms | 6796 KB | Output is correct |
24 | Correct | 402 ms | 6796 KB | Output is correct |
25 | Correct | 372 ms | 6892 KB | Output is correct |
26 | Correct | 417 ms | 6892 KB | Output is correct |
27 | Correct | 400 ms | 6892 KB | Output is correct |
28 | Correct | 256 ms | 7880 KB | Output is correct |
29 | Correct | 331 ms | 7880 KB | Output is correct |
30 | Correct | 371 ms | 7880 KB | Output is correct |
31 | Correct | 388 ms | 7880 KB | Output is correct |
32 | Correct | 437 ms | 7880 KB | Output is correct |
33 | Correct | 373 ms | 7880 KB | Output is correct |
34 | Correct | 432 ms | 7880 KB | Output is correct |
35 | Correct | 423 ms | 7880 KB | Output is correct |
36 | Correct | 255 ms | 7880 KB | Output is correct |
37 | Correct | 336 ms | 7880 KB | Output is correct |
38 | Correct | 350 ms | 7880 KB | Output is correct |
39 | Correct | 385 ms | 7880 KB | Output is correct |
40 | Correct | 425 ms | 7880 KB | Output is correct |
41 | Correct | 72 ms | 12228 KB | Output is correct |
42 | Correct | 77 ms | 12248 KB | Output is correct |
43 | Correct | 77 ms | 12248 KB | Output is correct |
44 | Correct | 134 ms | 12248 KB | Output is correct |
45 | Correct | 72 ms | 12356 KB | Output is correct |
46 | Correct | 90 ms | 12356 KB | Output is correct |
47 | Correct | 125 ms | 12356 KB | Output is correct |
48 | Correct | 62 ms | 12372 KB | Output is correct |
49 | Correct | 67 ms | 12372 KB | Output is correct |
50 | Correct | 71 ms | 12372 KB | Output is correct |
51 | Correct | 77 ms | 12372 KB | Output is correct |
52 | Correct | 86 ms | 12372 KB | Output is correct |
53 | Correct | 87 ms | 12372 KB | Output is correct |
54 | Correct | 93 ms | 12372 KB | Output is correct |
55 | Correct | 88 ms | 12372 KB | Output is correct |
56 | Correct | 61 ms | 12372 KB | Output is correct |
57 | Correct | 78 ms | 12372 KB | Output is correct |
58 | Correct | 72 ms | 12372 KB | Output is correct |
59 | Correct | 77 ms | 12372 KB | Output is correct |
60 | Correct | 76 ms | 12372 KB | Output is correct |
61 | Correct | 70 ms | 12372 KB | Output is correct |
62 | Correct | 87 ms | 12372 KB | Output is correct |
63 | Correct | 92 ms | 12372 KB | Output is correct |
64 | Correct | 59 ms | 12372 KB | Output is correct |
65 | Correct | 89 ms | 12372 KB | Output is correct |
66 | Correct | 82 ms | 12372 KB | Output is correct |
67 | Correct | 83 ms | 12372 KB | Output is correct |
68 | Correct | 81 ms | 12372 KB | Output is correct |
69 | Correct | 92 ms | 12372 KB | Output is correct |
70 | Correct | 92 ms | 12372 KB | Output is correct |
71 | Correct | 547 ms | 17028 KB | Output is correct |
72 | Correct | 560 ms | 17364 KB | Output is correct |
73 | Correct | 669 ms | 17364 KB | Output is correct |
74 | Correct | 850 ms | 17364 KB | Output is correct |
75 | Correct | 500 ms | 17888 KB | Output is correct |
76 | Correct | 875 ms | 17888 KB | Output is correct |
77 | Correct | 849 ms | 17888 KB | Output is correct |
78 | Correct | 345 ms | 19972 KB | Output is correct |
79 | Correct | 475 ms | 19972 KB | Output is correct |
80 | Correct | 589 ms | 19972 KB | Output is correct |
81 | Correct | 653 ms | 19972 KB | Output is correct |
82 | Correct | 745 ms | 19972 KB | Output is correct |
83 | Correct | 492 ms | 19972 KB | Output is correct |
84 | Correct | 899 ms | 19972 KB | Output is correct |
85 | Correct | 793 ms | 19972 KB | Output is correct |
86 | Correct | 360 ms | 19972 KB | Output is correct |
87 | Correct | 507 ms | 19972 KB | Output is correct |
88 | Correct | 474 ms | 19972 KB | Output is correct |
89 | Correct | 652 ms | 19972 KB | Output is correct |
90 | Correct | 629 ms | 19972 KB | Output is correct |
91 | Correct | 535 ms | 19972 KB | Output is correct |
92 | Correct | 995 ms | 19972 KB | Output is correct |
93 | Correct | 838 ms | 19972 KB | Output is correct |
94 | Correct | 361 ms | 19972 KB | Output is correct |
95 | Correct | 797 ms | 19972 KB | Output is correct |
96 | Correct | 815 ms | 37716 KB | Output is correct |
97 | Correct | 804 ms | 59312 KB | Output is correct |
98 | Runtime error | 848 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. |
99 | Halted | 0 ms | 0 KB | - |