# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
58965 | 2018-07-19T21:39:57 Z | TadijaSebez | Snake Escaping (JOI18_snake_escaping) | C++11 | 1522 ms | 40724 KB |
#include <stdio.h> const int N=1<<20; int dp0[N],dp1[N],pc[N]; char s[N],t[20]; int min(int a, int b){ return a>b?b:a;} int abs(int x){ return x>0?x:-x;} int main() { int n,q,i,mask; for(i=1;i<N;i++) pc[i]=pc[i-(i&-i)]+1; scanf("%i %i",&n,&q); scanf("%s",s); for(i=0;i<(1<<n);i++) { dp1[i]=dp0[((1<<n)-1)^i]=s[i]-'0'; } for(i=0;i<n;i++) { for(mask=0;mask<(1<<n);mask++) { if((mask>>i)&1) { dp1[mask]+=dp1[mask^(1<<i)]; dp0[mask]+=dp0[mask^(1<<i)]; } } } while(q--) { scanf("%s",t); int a=0,b=0,c=0; for(i=0;i<n;i++) { if(t[n-i-1]=='0') a+=1<<i; else if(t[n-i-1]=='1') b+=1<<i; else c+=1<<i; } int ans=0; if(pc[a]<=min(pc[b],pc[c])) { for(mask=a;;mask=(mask-1)&a) { //printf("a:%i %i\n",a,mask); if((pc[mask]&1)==(pc[a]&1)) ans+=dp0[mask|c]; else ans-=dp0[mask|c]; if(!mask) break; } } else if(pc[b]<=min(pc[a],pc[c])) { for(mask=b;;mask=(mask-1)&b) { //printf("b:%i %i\n",b,mask); if((pc[mask]&1)==(pc[b]&1)) ans+=dp1[mask|c]; else ans-=dp1[mask|c]; if(!mask) break; } } else { for(mask=c;;mask=(mask-1)&c) { //printf("c:%i %i\n",c,mask); ans+=s[mask|b]-'0'; if(!mask) break; } } printf("%i\n",abs(ans)); } return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 8 ms | 4472 KB | Output is correct |
2 | Correct | 7 ms | 4596 KB | Output is correct |
3 | Correct | 9 ms | 4596 KB | Output is correct |
4 | Correct | 8 ms | 4596 KB | Output is correct |
5 | Correct | 8 ms | 4596 KB | Output is correct |
6 | Correct | 7 ms | 4752 KB | Output is correct |
7 | Correct | 7 ms | 4752 KB | Output is correct |
8 | Correct | 7 ms | 4752 KB | Output is correct |
9 | Correct | 8 ms | 4752 KB | Output is correct |
10 | Correct | 7 ms | 4752 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 8 ms | 4472 KB | Output is correct |
2 | Correct | 7 ms | 4596 KB | Output is correct |
3 | Correct | 9 ms | 4596 KB | Output is correct |
4 | Correct | 8 ms | 4596 KB | Output is correct |
5 | Correct | 8 ms | 4596 KB | Output is correct |
6 | Correct | 7 ms | 4752 KB | Output is correct |
7 | Correct | 7 ms | 4752 KB | Output is correct |
8 | Correct | 7 ms | 4752 KB | Output is correct |
9 | Correct | 8 ms | 4752 KB | Output is correct |
10 | Correct | 7 ms | 4752 KB | Output is correct |
11 | Correct | 425 ms | 8832 KB | Output is correct |
12 | Correct | 366 ms | 8832 KB | Output is correct |
13 | Correct | 349 ms | 8832 KB | Output is correct |
14 | Correct | 440 ms | 8832 KB | Output is correct |
15 | Correct | 411 ms | 8972 KB | Output is correct |
16 | Correct | 404 ms | 8972 KB | Output is correct |
17 | Correct | 523 ms | 8972 KB | Output is correct |
18 | Correct | 343 ms | 9976 KB | Output is correct |
19 | Correct | 311 ms | 9976 KB | Output is correct |
20 | Correct | 417 ms | 9976 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 8 ms | 4472 KB | Output is correct |
2 | Correct | 7 ms | 4596 KB | Output is correct |
3 | Correct | 9 ms | 4596 KB | Output is correct |
4 | Correct | 8 ms | 4596 KB | Output is correct |
5 | Correct | 8 ms | 4596 KB | Output is correct |
6 | Correct | 7 ms | 4752 KB | Output is correct |
7 | Correct | 7 ms | 4752 KB | Output is correct |
8 | Correct | 7 ms | 4752 KB | Output is correct |
9 | Correct | 8 ms | 4752 KB | Output is correct |
10 | Correct | 7 ms | 4752 KB | Output is correct |
11 | Correct | 425 ms | 8832 KB | Output is correct |
12 | Correct | 366 ms | 8832 KB | Output is correct |
13 | Correct | 349 ms | 8832 KB | Output is correct |
14 | Correct | 440 ms | 8832 KB | Output is correct |
15 | Correct | 411 ms | 8972 KB | Output is correct |
16 | Correct | 404 ms | 8972 KB | Output is correct |
17 | Correct | 523 ms | 8972 KB | Output is correct |
18 | Correct | 343 ms | 9976 KB | Output is correct |
19 | Correct | 311 ms | 9976 KB | Output is correct |
20 | Correct | 417 ms | 9976 KB | Output is correct |
21 | Correct | 415 ms | 9976 KB | Output is correct |
22 | Correct | 401 ms | 9976 KB | Output is correct |
23 | Correct | 395 ms | 9976 KB | Output is correct |
24 | Correct | 534 ms | 9976 KB | Output is correct |
25 | Correct | 385 ms | 9976 KB | Output is correct |
26 | Correct | 522 ms | 9976 KB | Output is correct |
27 | Correct | 440 ms | 9976 KB | Output is correct |
28 | Correct | 293 ms | 10848 KB | Output is correct |
29 | Correct | 365 ms | 10848 KB | Output is correct |
30 | Correct | 397 ms | 10848 KB | Output is correct |
31 | Correct | 381 ms | 10848 KB | Output is correct |
32 | Correct | 396 ms | 10848 KB | Output is correct |
33 | Correct | 383 ms | 10848 KB | Output is correct |
34 | Correct | 429 ms | 10848 KB | Output is correct |
35 | Correct | 402 ms | 10848 KB | Output is correct |
36 | Correct | 270 ms | 10848 KB | Output is correct |
37 | Correct | 325 ms | 10848 KB | Output is correct |
38 | Correct | 374 ms | 10848 KB | Output is correct |
39 | Correct | 423 ms | 10848 KB | Output is correct |
40 | Correct | 420 ms | 10848 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 8 ms | 4472 KB | Output is correct |
2 | Correct | 7 ms | 4596 KB | Output is correct |
3 | Correct | 9 ms | 4596 KB | Output is correct |
4 | Correct | 8 ms | 4596 KB | Output is correct |
5 | Correct | 8 ms | 4596 KB | Output is correct |
6 | Correct | 7 ms | 4752 KB | Output is correct |
7 | Correct | 7 ms | 4752 KB | Output is correct |
8 | Correct | 7 ms | 4752 KB | Output is correct |
9 | Correct | 8 ms | 4752 KB | Output is correct |
10 | Correct | 7 ms | 4752 KB | Output is correct |
11 | Correct | 113 ms | 14440 KB | Output is correct |
12 | Correct | 107 ms | 14560 KB | Output is correct |
13 | Correct | 102 ms | 14560 KB | Output is correct |
14 | Correct | 124 ms | 14560 KB | Output is correct |
15 | Correct | 90 ms | 14560 KB | Output is correct |
16 | Correct | 171 ms | 14560 KB | Output is correct |
17 | Correct | 128 ms | 14560 KB | Output is correct |
18 | Correct | 68 ms | 14624 KB | Output is correct |
19 | Correct | 89 ms | 14624 KB | Output is correct |
20 | Correct | 83 ms | 14624 KB | Output is correct |
21 | Correct | 96 ms | 14624 KB | Output is correct |
22 | Correct | 124 ms | 14624 KB | Output is correct |
23 | Correct | 87 ms | 14624 KB | Output is correct |
24 | Correct | 129 ms | 14624 KB | Output is correct |
25 | Correct | 125 ms | 14624 KB | Output is correct |
26 | Correct | 76 ms | 14624 KB | Output is correct |
27 | Correct | 91 ms | 14624 KB | Output is correct |
28 | Correct | 91 ms | 14624 KB | Output is correct |
29 | Correct | 103 ms | 14624 KB | Output is correct |
30 | Correct | 80 ms | 14624 KB | Output is correct |
31 | Correct | 109 ms | 14624 KB | Output is correct |
32 | Correct | 104 ms | 14632 KB | Output is correct |
33 | Correct | 124 ms | 14632 KB | Output is correct |
34 | Correct | 71 ms | 14632 KB | Output is correct |
35 | Correct | 102 ms | 14632 KB | Output is correct |
36 | Correct | 136 ms | 14632 KB | Output is correct |
37 | Correct | 87 ms | 14632 KB | Output is correct |
38 | Correct | 120 ms | 14756 KB | Output is correct |
39 | Correct | 105 ms | 14756 KB | Output is correct |
40 | Correct | 105 ms | 14756 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 8 ms | 4472 KB | Output is correct |
2 | Correct | 7 ms | 4596 KB | Output is correct |
3 | Correct | 9 ms | 4596 KB | Output is correct |
4 | Correct | 8 ms | 4596 KB | Output is correct |
5 | Correct | 8 ms | 4596 KB | Output is correct |
6 | Correct | 7 ms | 4752 KB | Output is correct |
7 | Correct | 7 ms | 4752 KB | Output is correct |
8 | Correct | 7 ms | 4752 KB | Output is correct |
9 | Correct | 8 ms | 4752 KB | Output is correct |
10 | Correct | 7 ms | 4752 KB | Output is correct |
11 | Correct | 425 ms | 8832 KB | Output is correct |
12 | Correct | 366 ms | 8832 KB | Output is correct |
13 | Correct | 349 ms | 8832 KB | Output is correct |
14 | Correct | 440 ms | 8832 KB | Output is correct |
15 | Correct | 411 ms | 8972 KB | Output is correct |
16 | Correct | 404 ms | 8972 KB | Output is correct |
17 | Correct | 523 ms | 8972 KB | Output is correct |
18 | Correct | 343 ms | 9976 KB | Output is correct |
19 | Correct | 311 ms | 9976 KB | Output is correct |
20 | Correct | 417 ms | 9976 KB | Output is correct |
21 | Correct | 415 ms | 9976 KB | Output is correct |
22 | Correct | 401 ms | 9976 KB | Output is correct |
23 | Correct | 395 ms | 9976 KB | Output is correct |
24 | Correct | 534 ms | 9976 KB | Output is correct |
25 | Correct | 385 ms | 9976 KB | Output is correct |
26 | Correct | 522 ms | 9976 KB | Output is correct |
27 | Correct | 440 ms | 9976 KB | Output is correct |
28 | Correct | 293 ms | 10848 KB | Output is correct |
29 | Correct | 365 ms | 10848 KB | Output is correct |
30 | Correct | 397 ms | 10848 KB | Output is correct |
31 | Correct | 381 ms | 10848 KB | Output is correct |
32 | Correct | 396 ms | 10848 KB | Output is correct |
33 | Correct | 383 ms | 10848 KB | Output is correct |
34 | Correct | 429 ms | 10848 KB | Output is correct |
35 | Correct | 402 ms | 10848 KB | Output is correct |
36 | Correct | 270 ms | 10848 KB | Output is correct |
37 | Correct | 325 ms | 10848 KB | Output is correct |
38 | Correct | 374 ms | 10848 KB | Output is correct |
39 | Correct | 423 ms | 10848 KB | Output is correct |
40 | Correct | 420 ms | 10848 KB | Output is correct |
41 | Correct | 113 ms | 14440 KB | Output is correct |
42 | Correct | 107 ms | 14560 KB | Output is correct |
43 | Correct | 102 ms | 14560 KB | Output is correct |
44 | Correct | 124 ms | 14560 KB | Output is correct |
45 | Correct | 90 ms | 14560 KB | Output is correct |
46 | Correct | 171 ms | 14560 KB | Output is correct |
47 | Correct | 128 ms | 14560 KB | Output is correct |
48 | Correct | 68 ms | 14624 KB | Output is correct |
49 | Correct | 89 ms | 14624 KB | Output is correct |
50 | Correct | 83 ms | 14624 KB | Output is correct |
51 | Correct | 96 ms | 14624 KB | Output is correct |
52 | Correct | 124 ms | 14624 KB | Output is correct |
53 | Correct | 87 ms | 14624 KB | Output is correct |
54 | Correct | 129 ms | 14624 KB | Output is correct |
55 | Correct | 125 ms | 14624 KB | Output is correct |
56 | Correct | 76 ms | 14624 KB | Output is correct |
57 | Correct | 91 ms | 14624 KB | Output is correct |
58 | Correct | 91 ms | 14624 KB | Output is correct |
59 | Correct | 103 ms | 14624 KB | Output is correct |
60 | Correct | 80 ms | 14624 KB | Output is correct |
61 | Correct | 109 ms | 14624 KB | Output is correct |
62 | Correct | 104 ms | 14632 KB | Output is correct |
63 | Correct | 124 ms | 14632 KB | Output is correct |
64 | Correct | 71 ms | 14632 KB | Output is correct |
65 | Correct | 102 ms | 14632 KB | Output is correct |
66 | Correct | 136 ms | 14632 KB | Output is correct |
67 | Correct | 87 ms | 14632 KB | Output is correct |
68 | Correct | 120 ms | 14756 KB | Output is correct |
69 | Correct | 105 ms | 14756 KB | Output is correct |
70 | Correct | 105 ms | 14756 KB | Output is correct |
71 | Correct | 789 ms | 19280 KB | Output is correct |
72 | Correct | 582 ms | 19536 KB | Output is correct |
73 | Correct | 690 ms | 19536 KB | Output is correct |
74 | Correct | 871 ms | 19536 KB | Output is correct |
75 | Correct | 597 ms | 20660 KB | Output is correct |
76 | Correct | 1002 ms | 20660 KB | Output is correct |
77 | Correct | 939 ms | 20660 KB | Output is correct |
78 | Correct | 373 ms | 22556 KB | Output is correct |
79 | Correct | 709 ms | 22556 KB | Output is correct |
80 | Correct | 791 ms | 22556 KB | Output is correct |
81 | Correct | 802 ms | 22556 KB | Output is correct |
82 | Correct | 1285 ms | 22556 KB | Output is correct |
83 | Correct | 779 ms | 22556 KB | Output is correct |
84 | Correct | 1477 ms | 22556 KB | Output is correct |
85 | Correct | 986 ms | 22556 KB | Output is correct |
86 | Correct | 391 ms | 22556 KB | Output is correct |
87 | Correct | 547 ms | 22556 KB | Output is correct |
88 | Correct | 578 ms | 22556 KB | Output is correct |
89 | Correct | 705 ms | 22556 KB | Output is correct |
90 | Correct | 922 ms | 22556 KB | Output is correct |
91 | Correct | 623 ms | 39772 KB | Output is correct |
92 | Correct | 1522 ms | 40716 KB | Output is correct |
93 | Correct | 1069 ms | 40716 KB | Output is correct |
94 | Correct | 341 ms | 40716 KB | Output is correct |
95 | Correct | 937 ms | 40716 KB | Output is correct |
96 | Correct | 936 ms | 40724 KB | Output is correct |
97 | Correct | 929 ms | 40724 KB | Output is correct |
98 | Correct | 985 ms | 40724 KB | Output is correct |
99 | Correct | 1036 ms | 40724 KB | Output is correct |
100 | Correct | 939 ms | 40724 KB | Output is correct |