# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
161423 | 2019-11-02T10:54:56 Z | HungAnhGoldIBO2020 | Snake Escaping (JOI18_snake_escaping) | C++14 | 1185 ms | 43416 KB |
#include<bits/stdc++.h> using namespace std; const int N=1e6+1e5; int f0[N],f1[N],val[N]; signed main(){ ios::sync_with_stdio(0); cin.tie(0); int q,n,m,i,j,k,l,m1,m2,m3,ans; cin>>n>>q; string s; cin>>s; k=(1<<n)-1; for(i=0;i<=k;i++){ val[i]=f1[i]=f0[k^i]=s[i]-'0'; } for(i=0;i<n;i++){ for(j=0;j<=k;j++){ if((j&(1<<i))){ f1[j]+=f1[j^(1<<i)]; f0[j]+=f0[j^(1<<i)]; } } } // cout<<f0[4]<<' '<<f0[0]<<endl; for(i=1;i<=q;i++){ m1=m2=m3=ans=0; cin>>s; for(j=0;j<n;j++){ if(s[n-j-1]=='0'){ m1|=(1<<j); } if(s[n-j-1]=='1'){ m2|=(1<<j); } if(s[n-j-1]=='?'){ m3|=(1<<j); } } if(__builtin_popcount(m1)<=n/3){ for(j=m1;j;j=(j-1)&m1){ if((__builtin_popcount(m1)&1)==(__builtin_popcount(j)&1)){ ans+=f0[m3|j]; } else{ ans-=f0[m3|j]; } } // cout<<m3<<'\n'; if((__builtin_popcount(m1)&1)==(__builtin_popcount(j)&1)){ ans+=f0[m3|j]; } else{ ans-=f0[m3|j]; } cout<<ans<<'\n'; // cout<<"cac"<<'\n'; continue; } if(__builtin_popcount(m2)<=n/3){ for(j=m2;j;j=(j-1)&m2){ if((__builtin_popcount(m2)&1)==(__builtin_popcount(j)&1)){ ans+=f1[m3|j]; } else{ ans-=f1[m3|j]; } } if((__builtin_popcount(m2)&1)==(__builtin_popcount(j)&1)){ ans+=f1[m3|j]; } else{ ans-=f1[m3|j]; } cout<<ans<<'\n'; continue; } if(__builtin_popcount(m3)<=n/3){ ans=val[m2]; for(j=m3;j;j=(j-1)&m3){ ans+=val[m2|j]; } cout<<ans<<'\n'; continue; } } }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 428 KB | Output is correct |
2 | Correct | 2 ms | 376 KB | Output is correct |
3 | Correct | 3 ms | 376 KB | Output is correct |
4 | Correct | 2 ms | 428 KB | Output is correct |
5 | Correct | 3 ms | 376 KB | Output is correct |
6 | Correct | 2 ms | 376 KB | Output is correct |
7 | Correct | 2 ms | 376 KB | Output is correct |
8 | Correct | 2 ms | 428 KB | Output is correct |
9 | Correct | 2 ms | 376 KB | Output is correct |
10 | Correct | 2 ms | 376 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 428 KB | Output is correct |
2 | Correct | 2 ms | 376 KB | Output is correct |
3 | Correct | 3 ms | 376 KB | Output is correct |
4 | Correct | 2 ms | 428 KB | Output is correct |
5 | Correct | 3 ms | 376 KB | Output is correct |
6 | Correct | 2 ms | 376 KB | Output is correct |
7 | Correct | 2 ms | 376 KB | Output is correct |
8 | Correct | 2 ms | 428 KB | Output is correct |
9 | Correct | 2 ms | 376 KB | Output is correct |
10 | Correct | 2 ms | 376 KB | Output is correct |
11 | Correct | 250 ms | 15184 KB | Output is correct |
12 | Correct | 279 ms | 14820 KB | Output is correct |
13 | Correct | 321 ms | 14152 KB | Output is correct |
14 | Correct | 340 ms | 14200 KB | Output is correct |
15 | Correct | 284 ms | 15132 KB | Output is correct |
16 | Correct | 313 ms | 14432 KB | Output is correct |
17 | Correct | 313 ms | 14452 KB | Output is correct |
18 | Correct | 203 ms | 16248 KB | Output is correct |
19 | Correct | 253 ms | 13176 KB | Output is correct |
20 | Correct | 266 ms | 14840 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 428 KB | Output is correct |
2 | Correct | 2 ms | 376 KB | Output is correct |
3 | Correct | 3 ms | 376 KB | Output is correct |
4 | Correct | 2 ms | 428 KB | Output is correct |
5 | Correct | 3 ms | 376 KB | Output is correct |
6 | Correct | 2 ms | 376 KB | Output is correct |
7 | Correct | 2 ms | 376 KB | Output is correct |
8 | Correct | 2 ms | 428 KB | Output is correct |
9 | Correct | 2 ms | 376 KB | Output is correct |
10 | Correct | 2 ms | 376 KB | Output is correct |
11 | Correct | 250 ms | 15184 KB | Output is correct |
12 | Correct | 279 ms | 14820 KB | Output is correct |
13 | Correct | 321 ms | 14152 KB | Output is correct |
14 | Correct | 340 ms | 14200 KB | Output is correct |
15 | Correct | 284 ms | 15132 KB | Output is correct |
16 | Correct | 313 ms | 14432 KB | Output is correct |
17 | Correct | 313 ms | 14452 KB | Output is correct |
18 | Correct | 203 ms | 16248 KB | Output is correct |
19 | Correct | 253 ms | 13176 KB | Output is correct |
20 | Correct | 266 ms | 14840 KB | Output is correct |
21 | Correct | 284 ms | 18280 KB | Output is correct |
22 | Correct | 312 ms | 18432 KB | Output is correct |
23 | Correct | 367 ms | 17528 KB | Output is correct |
24 | Correct | 422 ms | 17268 KB | Output is correct |
25 | Correct | 341 ms | 19184 KB | Output is correct |
26 | Correct | 405 ms | 17796 KB | Output is correct |
27 | Correct | 374 ms | 17656 KB | Output is correct |
28 | Correct | 233 ms | 20348 KB | Output is correct |
29 | Correct | 283 ms | 16232 KB | Output is correct |
30 | Correct | 314 ms | 18420 KB | Output is correct |
31 | Correct | 356 ms | 18164 KB | Output is correct |
32 | Correct | 401 ms | 18296 KB | Output is correct |
33 | Correct | 317 ms | 17116 KB | Output is correct |
34 | Correct | 379 ms | 17272 KB | Output is correct |
35 | Correct | 392 ms | 17756 KB | Output is correct |
36 | Correct | 199 ms | 16372 KB | Output is correct |
37 | Correct | 300 ms | 18372 KB | Output is correct |
38 | Correct | 316 ms | 16372 KB | Output is correct |
39 | Correct | 370 ms | 17444 KB | Output is correct |
40 | Correct | 392 ms | 17272 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 428 KB | Output is correct |
2 | Correct | 2 ms | 376 KB | Output is correct |
3 | Correct | 3 ms | 376 KB | Output is correct |
4 | Correct | 2 ms | 428 KB | Output is correct |
5 | Correct | 3 ms | 376 KB | Output is correct |
6 | Correct | 2 ms | 376 KB | Output is correct |
7 | Correct | 2 ms | 376 KB | Output is correct |
8 | Correct | 2 ms | 428 KB | Output is correct |
9 | Correct | 2 ms | 376 KB | Output is correct |
10 | Correct | 2 ms | 376 KB | Output is correct |
11 | Correct | 73 ms | 16152 KB | Output is correct |
12 | Correct | 71 ms | 16172 KB | Output is correct |
13 | Correct | 83 ms | 16156 KB | Output is correct |
14 | Correct | 95 ms | 16228 KB | Output is correct |
15 | Correct | 166 ms | 16152 KB | Output is correct |
16 | Correct | 95 ms | 16140 KB | Output is correct |
17 | Correct | 90 ms | 16152 KB | Output is correct |
18 | Correct | 60 ms | 16276 KB | Output is correct |
19 | Correct | 67 ms | 16032 KB | Output is correct |
20 | Correct | 69 ms | 16280 KB | Output is correct |
21 | Correct | 80 ms | 16280 KB | Output is correct |
22 | Correct | 89 ms | 16024 KB | Output is correct |
23 | Correct | 68 ms | 16020 KB | Output is correct |
24 | Correct | 98 ms | 16044 KB | Output is correct |
25 | Correct | 95 ms | 16028 KB | Output is correct |
26 | Correct | 61 ms | 16020 KB | Output is correct |
27 | Correct | 68 ms | 16152 KB | Output is correct |
28 | Correct | 71 ms | 15940 KB | Output is correct |
29 | Correct | 78 ms | 16028 KB | Output is correct |
30 | Correct | 79 ms | 16284 KB | Output is correct |
31 | Correct | 130 ms | 16064 KB | Output is correct |
32 | Correct | 109 ms | 16228 KB | Output is correct |
33 | Correct | 100 ms | 16252 KB | Output is correct |
34 | Correct | 59 ms | 16024 KB | Output is correct |
35 | Correct | 88 ms | 16152 KB | Output is correct |
36 | Correct | 87 ms | 16152 KB | Output is correct |
37 | Correct | 88 ms | 16024 KB | Output is correct |
38 | Correct | 85 ms | 16028 KB | Output is correct |
39 | Correct | 90 ms | 16120 KB | Output is correct |
40 | Correct | 100 ms | 16156 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 428 KB | Output is correct |
2 | Correct | 2 ms | 376 KB | Output is correct |
3 | Correct | 3 ms | 376 KB | Output is correct |
4 | Correct | 2 ms | 428 KB | Output is correct |
5 | Correct | 3 ms | 376 KB | Output is correct |
6 | Correct | 2 ms | 376 KB | Output is correct |
7 | Correct | 2 ms | 376 KB | Output is correct |
8 | Correct | 2 ms | 428 KB | Output is correct |
9 | Correct | 2 ms | 376 KB | Output is correct |
10 | Correct | 2 ms | 376 KB | Output is correct |
11 | Correct | 250 ms | 15184 KB | Output is correct |
12 | Correct | 279 ms | 14820 KB | Output is correct |
13 | Correct | 321 ms | 14152 KB | Output is correct |
14 | Correct | 340 ms | 14200 KB | Output is correct |
15 | Correct | 284 ms | 15132 KB | Output is correct |
16 | Correct | 313 ms | 14432 KB | Output is correct |
17 | Correct | 313 ms | 14452 KB | Output is correct |
18 | Correct | 203 ms | 16248 KB | Output is correct |
19 | Correct | 253 ms | 13176 KB | Output is correct |
20 | Correct | 266 ms | 14840 KB | Output is correct |
21 | Correct | 284 ms | 18280 KB | Output is correct |
22 | Correct | 312 ms | 18432 KB | Output is correct |
23 | Correct | 367 ms | 17528 KB | Output is correct |
24 | Correct | 422 ms | 17268 KB | Output is correct |
25 | Correct | 341 ms | 19184 KB | Output is correct |
26 | Correct | 405 ms | 17796 KB | Output is correct |
27 | Correct | 374 ms | 17656 KB | Output is correct |
28 | Correct | 233 ms | 20348 KB | Output is correct |
29 | Correct | 283 ms | 16232 KB | Output is correct |
30 | Correct | 314 ms | 18420 KB | Output is correct |
31 | Correct | 356 ms | 18164 KB | Output is correct |
32 | Correct | 401 ms | 18296 KB | Output is correct |
33 | Correct | 317 ms | 17116 KB | Output is correct |
34 | Correct | 379 ms | 17272 KB | Output is correct |
35 | Correct | 392 ms | 17756 KB | Output is correct |
36 | Correct | 199 ms | 16372 KB | Output is correct |
37 | Correct | 300 ms | 18372 KB | Output is correct |
38 | Correct | 316 ms | 16372 KB | Output is correct |
39 | Correct | 370 ms | 17444 KB | Output is correct |
40 | Correct | 392 ms | 17272 KB | Output is correct |
41 | Correct | 73 ms | 16152 KB | Output is correct |
42 | Correct | 71 ms | 16172 KB | Output is correct |
43 | Correct | 83 ms | 16156 KB | Output is correct |
44 | Correct | 95 ms | 16228 KB | Output is correct |
45 | Correct | 166 ms | 16152 KB | Output is correct |
46 | Correct | 95 ms | 16140 KB | Output is correct |
47 | Correct | 90 ms | 16152 KB | Output is correct |
48 | Correct | 60 ms | 16276 KB | Output is correct |
49 | Correct | 67 ms | 16032 KB | Output is correct |
50 | Correct | 69 ms | 16280 KB | Output is correct |
51 | Correct | 80 ms | 16280 KB | Output is correct |
52 | Correct | 89 ms | 16024 KB | Output is correct |
53 | Correct | 68 ms | 16020 KB | Output is correct |
54 | Correct | 98 ms | 16044 KB | Output is correct |
55 | Correct | 95 ms | 16028 KB | Output is correct |
56 | Correct | 61 ms | 16020 KB | Output is correct |
57 | Correct | 68 ms | 16152 KB | Output is correct |
58 | Correct | 71 ms | 15940 KB | Output is correct |
59 | Correct | 78 ms | 16028 KB | Output is correct |
60 | Correct | 79 ms | 16284 KB | Output is correct |
61 | Correct | 130 ms | 16064 KB | Output is correct |
62 | Correct | 109 ms | 16228 KB | Output is correct |
63 | Correct | 100 ms | 16252 KB | Output is correct |
64 | Correct | 59 ms | 16024 KB | Output is correct |
65 | Correct | 88 ms | 16152 KB | Output is correct |
66 | Correct | 87 ms | 16152 KB | Output is correct |
67 | Correct | 88 ms | 16024 KB | Output is correct |
68 | Correct | 85 ms | 16028 KB | Output is correct |
69 | Correct | 90 ms | 16120 KB | Output is correct |
70 | Correct | 100 ms | 16156 KB | Output is correct |
71 | Correct | 460 ms | 40656 KB | Output is correct |
72 | Correct | 504 ms | 40724 KB | Output is correct |
73 | Correct | 697 ms | 39128 KB | Output is correct |
74 | Correct | 942 ms | 39504 KB | Output is correct |
75 | Correct | 513 ms | 41608 KB | Output is correct |
76 | Correct | 1026 ms | 39828 KB | Output is correct |
77 | Correct | 1059 ms | 39752 KB | Output is correct |
78 | Correct | 310 ms | 43416 KB | Output is correct |
79 | Correct | 440 ms | 37544 KB | Output is correct |
80 | Correct | 497 ms | 40600 KB | Output is correct |
81 | Correct | 681 ms | 40600 KB | Output is correct |
82 | Correct | 837 ms | 39608 KB | Output is correct |
83 | Correct | 487 ms | 38680 KB | Output is correct |
84 | Correct | 1185 ms | 39596 KB | Output is correct |
85 | Correct | 969 ms | 39824 KB | Output is correct |
86 | Correct | 266 ms | 37528 KB | Output is correct |
87 | Correct | 474 ms | 40468 KB | Output is correct |
88 | Correct | 518 ms | 37388 KB | Output is correct |
89 | Correct | 658 ms | 39212 KB | Output is correct |
90 | Correct | 585 ms | 39664 KB | Output is correct |
91 | Correct | 519 ms | 38660 KB | Output is correct |
92 | Correct | 1028 ms | 39796 KB | Output is correct |
93 | Correct | 1049 ms | 39852 KB | Output is correct |
94 | Correct | 267 ms | 37508 KB | Output is correct |
95 | Correct | 845 ms | 39636 KB | Output is correct |
96 | Correct | 892 ms | 39840 KB | Output is correct |
97 | Correct | 880 ms | 39608 KB | Output is correct |
98 | Correct | 847 ms | 39460 KB | Output is correct |
99 | Correct | 891 ms | 39664 KB | Output is correct |
100 | Correct | 828 ms | 39440 KB | Output is correct |