Submission #713719

# Submission time Handle Problem Language Result Execution time Memory
713719 2023-03-22T23:28:14 Z EthanKim8683 Snake Escaping (JOI18_snake_escaping) C++17
100 / 100
1228 ms 43332 KB
#include<bits/stdc++.h>
using namespace std;
using I=int;
using S=string;
using C=char;
const I L=20;
I dp[3][1<<L];
vector<I>dgts;
I main(){
  cin.tie(0)->sync_with_stdio(0);
  I l,q;cin>>l>>q;
  S s;cin>>s;
  for(I i=0;i<(1<<l);i++)for(I j=0;j<3;j++)dp[j][i]=s[i]-'0';
  for(I i=1;i<=l;i++)for(I j=0;j<(1<<l);j+=1<<i)for(I k=0;k<(1<<(i-1));k++){
    dp[0][j+k+(1<<(i-1))]+=dp[0][j+k];
    dp[1][j+k]+=dp[1][j+k+(1<<(i-1))];
  }
  for(I i=0;i<q;i++){
    S t;cin>>t;
    I cnt1=0,cnt2=0,cnt3=0;
    for(auto c:t)cnt1+=c=='1',cnt2+=c=='0',cnt3+=c=='?';
    C x,y,z;I typ;
    if(cnt1<=cnt2&&cnt1<=cnt3)x='1',y='0',z='?',typ=0;
    if(cnt2<=cnt1&&cnt2<=cnt3)x='0',y='?',z='1',typ=1;
    if(cnt3<=cnt1&&cnt3<=cnt2)x='?',y='0',z='1',typ=2;
    dgts.clear();
    I res=0,idx=0;
    for(I j=0;j<l;j++){
      if(t[l-1-j]==x)dgts.push_back(1<<j);
      if(t[l-1-j]==y)idx|=0<<j;
      if(t[l-1-j]==z)idx|=1<<j;
    }
    res+=dp[typ][idx];
    for(I j=1;j<(1<<dgts.size());j++){
      for(I k=(j-1)^j;k;k-=k&-k)idx^=dgts[__builtin_ctz(k)];
      res+=dp[typ][idx]*(typ==2?1:1-__builtin_popcount(j)%2*2);
    }
    printf("%i\n",abs(res));
  }
}

Compilation message

snake_escaping.cpp: In function 'I main()':
snake_escaping.cpp:36:23: warning: 'typ' may be used uninitialized in this function [-Wmaybe-uninitialized]
   36 |       res+=dp[typ][idx]*(typ==2?1:1-__builtin_popcount(j)%2*2);
      |            ~~~~~~~~~~~^
snake_escaping.cpp:31:7: warning: 'z' may be used uninitialized in this function [-Wmaybe-uninitialized]
   31 |       if(t[l-1-j]==z)idx|=1<<j;
      |       ^~
snake_escaping.cpp:29:7: warning: 'x' may be used uninitialized in this function [-Wmaybe-uninitialized]
   29 |       if(t[l-1-j]==x)dgts.push_back(1<<j);
      |       ^~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 222 ms 15012 KB Output is correct
12 Correct 241 ms 14692 KB Output is correct
13 Correct 256 ms 13996 KB Output is correct
14 Correct 260 ms 14084 KB Output is correct
15 Correct 258 ms 15076 KB Output is correct
16 Correct 275 ms 14184 KB Output is correct
17 Correct 269 ms 14160 KB Output is correct
18 Correct 194 ms 16080 KB Output is correct
19 Correct 217 ms 13056 KB Output is correct
20 Correct 236 ms 14688 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 222 ms 15012 KB Output is correct
12 Correct 241 ms 14692 KB Output is correct
13 Correct 256 ms 13996 KB Output is correct
14 Correct 260 ms 14084 KB Output is correct
15 Correct 258 ms 15076 KB Output is correct
16 Correct 275 ms 14184 KB Output is correct
17 Correct 269 ms 14160 KB Output is correct
18 Correct 194 ms 16080 KB Output is correct
19 Correct 217 ms 13056 KB Output is correct
20 Correct 236 ms 14688 KB Output is correct
21 Correct 253 ms 18056 KB Output is correct
22 Correct 273 ms 18316 KB Output is correct
23 Correct 310 ms 17308 KB Output is correct
24 Correct 336 ms 17128 KB Output is correct
25 Correct 306 ms 19072 KB Output is correct
26 Correct 342 ms 17656 KB Output is correct
27 Correct 319 ms 17612 KB Output is correct
28 Correct 221 ms 20104 KB Output is correct
29 Correct 251 ms 16144 KB Output is correct
30 Correct 269 ms 18424 KB Output is correct
31 Correct 310 ms 18092 KB Output is correct
32 Correct 363 ms 18064 KB Output is correct
33 Correct 275 ms 17140 KB Output is correct
34 Correct 323 ms 17076 KB Output is correct
35 Correct 340 ms 17616 KB Output is correct
36 Correct 206 ms 16108 KB Output is correct
37 Correct 249 ms 18092 KB Output is correct
38 Correct 267 ms 16212 KB Output is correct
39 Correct 304 ms 17344 KB Output is correct
40 Correct 326 ms 17060 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 41 ms 15984 KB Output is correct
12 Correct 44 ms 16040 KB Output is correct
13 Correct 57 ms 15980 KB Output is correct
14 Correct 68 ms 15940 KB Output is correct
15 Correct 43 ms 16048 KB Output is correct
16 Correct 80 ms 15992 KB Output is correct
17 Correct 67 ms 15936 KB Output is correct
18 Correct 36 ms 16192 KB Output is correct
19 Correct 47 ms 16028 KB Output is correct
20 Correct 42 ms 16084 KB Output is correct
21 Correct 55 ms 15992 KB Output is correct
22 Correct 70 ms 15940 KB Output is correct
23 Correct 42 ms 15948 KB Output is correct
24 Correct 75 ms 15968 KB Output is correct
25 Correct 67 ms 15996 KB Output is correct
26 Correct 35 ms 15852 KB Output is correct
27 Correct 40 ms 16084 KB Output is correct
28 Correct 43 ms 15916 KB Output is correct
29 Correct 48 ms 16008 KB Output is correct
30 Correct 58 ms 15976 KB Output is correct
31 Correct 42 ms 15956 KB Output is correct
32 Correct 85 ms 15996 KB Output is correct
33 Correct 70 ms 16044 KB Output is correct
34 Correct 46 ms 15908 KB Output is correct
35 Correct 90 ms 15972 KB Output is correct
36 Correct 76 ms 15952 KB Output is correct
37 Correct 71 ms 15960 KB Output is correct
38 Correct 73 ms 16028 KB Output is correct
39 Correct 74 ms 15984 KB Output is correct
40 Correct 88 ms 15940 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 222 ms 15012 KB Output is correct
12 Correct 241 ms 14692 KB Output is correct
13 Correct 256 ms 13996 KB Output is correct
14 Correct 260 ms 14084 KB Output is correct
15 Correct 258 ms 15076 KB Output is correct
16 Correct 275 ms 14184 KB Output is correct
17 Correct 269 ms 14160 KB Output is correct
18 Correct 194 ms 16080 KB Output is correct
19 Correct 217 ms 13056 KB Output is correct
20 Correct 236 ms 14688 KB Output is correct
21 Correct 253 ms 18056 KB Output is correct
22 Correct 273 ms 18316 KB Output is correct
23 Correct 310 ms 17308 KB Output is correct
24 Correct 336 ms 17128 KB Output is correct
25 Correct 306 ms 19072 KB Output is correct
26 Correct 342 ms 17656 KB Output is correct
27 Correct 319 ms 17612 KB Output is correct
28 Correct 221 ms 20104 KB Output is correct
29 Correct 251 ms 16144 KB Output is correct
30 Correct 269 ms 18424 KB Output is correct
31 Correct 310 ms 18092 KB Output is correct
32 Correct 363 ms 18064 KB Output is correct
33 Correct 275 ms 17140 KB Output is correct
34 Correct 323 ms 17076 KB Output is correct
35 Correct 340 ms 17616 KB Output is correct
36 Correct 206 ms 16108 KB Output is correct
37 Correct 249 ms 18092 KB Output is correct
38 Correct 267 ms 16212 KB Output is correct
39 Correct 304 ms 17344 KB Output is correct
40 Correct 326 ms 17060 KB Output is correct
41 Correct 41 ms 15984 KB Output is correct
42 Correct 44 ms 16040 KB Output is correct
43 Correct 57 ms 15980 KB Output is correct
44 Correct 68 ms 15940 KB Output is correct
45 Correct 43 ms 16048 KB Output is correct
46 Correct 80 ms 15992 KB Output is correct
47 Correct 67 ms 15936 KB Output is correct
48 Correct 36 ms 16192 KB Output is correct
49 Correct 47 ms 16028 KB Output is correct
50 Correct 42 ms 16084 KB Output is correct
51 Correct 55 ms 15992 KB Output is correct
52 Correct 70 ms 15940 KB Output is correct
53 Correct 42 ms 15948 KB Output is correct
54 Correct 75 ms 15968 KB Output is correct
55 Correct 67 ms 15996 KB Output is correct
56 Correct 35 ms 15852 KB Output is correct
57 Correct 40 ms 16084 KB Output is correct
58 Correct 43 ms 15916 KB Output is correct
59 Correct 48 ms 16008 KB Output is correct
60 Correct 58 ms 15976 KB Output is correct
61 Correct 42 ms 15956 KB Output is correct
62 Correct 85 ms 15996 KB Output is correct
63 Correct 70 ms 16044 KB Output is correct
64 Correct 46 ms 15908 KB Output is correct
65 Correct 90 ms 15972 KB Output is correct
66 Correct 76 ms 15952 KB Output is correct
67 Correct 71 ms 15960 KB Output is correct
68 Correct 73 ms 16028 KB Output is correct
69 Correct 74 ms 15984 KB Output is correct
70 Correct 88 ms 15940 KB Output is correct
71 Correct 505 ms 40276 KB Output is correct
72 Correct 435 ms 40548 KB Output is correct
73 Correct 608 ms 38988 KB Output is correct
74 Correct 917 ms 39368 KB Output is correct
75 Correct 451 ms 41280 KB Output is correct
76 Correct 1063 ms 39768 KB Output is correct
77 Correct 961 ms 39552 KB Output is correct
78 Correct 302 ms 43332 KB Output is correct
79 Correct 431 ms 37312 KB Output is correct
80 Correct 439 ms 40428 KB Output is correct
81 Correct 671 ms 40552 KB Output is correct
82 Correct 935 ms 39268 KB Output is correct
83 Correct 436 ms 38552 KB Output is correct
84 Correct 966 ms 39304 KB Output is correct
85 Correct 980 ms 39492 KB Output is correct
86 Correct 304 ms 37380 KB Output is correct
87 Correct 417 ms 40352 KB Output is correct
88 Correct 444 ms 37344 KB Output is correct
89 Correct 618 ms 39020 KB Output is correct
90 Correct 743 ms 39304 KB Output is correct
91 Correct 426 ms 38520 KB Output is correct
92 Correct 1228 ms 39728 KB Output is correct
93 Correct 1010 ms 39552 KB Output is correct
94 Correct 310 ms 37268 KB Output is correct
95 Correct 796 ms 39368 KB Output is correct
96 Correct 789 ms 39548 KB Output is correct
97 Correct 807 ms 39688 KB Output is correct
98 Correct 760 ms 39392 KB Output is correct
99 Correct 790 ms 39596 KB Output is correct
100 Correct 799 ms 39428 KB Output is correct