# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
331814 | 2020-11-30T08:45:18 Z | daniel920712 | Snake Escaping (JOI18_snake_escaping) | C++14 | 1955 ms | 55660 KB |
#include <iostream> #include <stdio.h> #include <stdlib.h> #include <vector> #include <string.h> #include <map> #include <utility> #include <algorithm> #include <stack> #include <queue> using namespace std; char all[1148576]; char tt[25]; int con1[2][1100005]; int con2[2][1100005]; int Con1[1100005]; int Con2[1100005]; int ans=0; int N; vector < int > xxx; vector < pair < int , int > > BFS,ttt; int main() { //freopen("05-04.txt","rt",stdin); //freopen("aa.txt","w+t",stdout); int M,i,j,ok,a,b,c,x,y,z,con=0,xx; scanf("%d %d",&N,&M); scanf("%s",all); for(i=0;i<(1<<N);i++) con2[0][i]=con1[0][i]=all[i]-'0'; for(i=0;i<N;i++) { for(j=0;j<(1<<N);j++) { con1[1-i%2][j]=con1[i%2][j]; con2[1-i%2][j]=con2[i%2][j]; if(j&(1<<i)) con1[1-i%2][j]+=con1[i%2][j-(1<<i)]; else con2[1-i%2][j]+=con2[i%2][j+(1<<i)]; } } for(j=0;j<(1<<N);j++) { Con1[j]=con1[N%2][j]; Con2[j]=con2[N%2][j]; } while(M--) { scanf("%s",tt); BFS.clear(); ans=0; a=0; b=0; c=0; for(i=0;i<N;i++) { if(tt[i]=='?') a++; else if(tt[i]=='1') b++; else c++; } xxx.clear(); con=0; if(b<=a&&b<=c) { //printf("aa\n"); for(i=0;i<N;i++) { if(tt[i]=='1') xxx.push_back((1<<(N-i-1))); else if(tt[i]=='?') con+=(1<<(N-i-1)); } BFS.push_back(make_pair(con,0)); for(auto i:xxx) { ttt.clear(); for(auto &j:BFS) { ttt.push_back(make_pair(j.first+i,j.second)); j.second^=1; } for(auto j:ttt) BFS.push_back(j); } for(auto i:BFS) { if(i.second) ans-=Con1[i.first]; else ans+=Con1[i.first]; } } else if(a<=b&&a<=c) { for(i=0;i<N;i++) { if(tt[i]=='?') xxx.push_back((1<<(N-i-1))); else if(tt[i]=='1') con+=(1<<(N-i-1)); } BFS.push_back(make_pair(con,0)); for(auto i:xxx) { ttt.clear(); for(auto &j:BFS) ttt.push_back(make_pair(j.first+i,j.second)); for(auto j:ttt) BFS.push_back(j); } for(auto i:BFS) ans+=(all[i.first]-'0'); } else if(c<=b&&c<=a) { for(i=0;i<N;i++) { if(tt[i]=='0') xxx.push_back((1<<(N-i-1))); else if(tt[i]=='1') con+=(1<<(N-i-1)); } BFS.push_back(make_pair(con,0)); for(auto i:xxx) { ttt.clear(); for(auto &j:BFS) ttt.push_back(make_pair(j.first+i,j.second^1)); for(auto j:ttt) BFS.push_back(j); } for(auto i:BFS) { if(i.second) ans-=Con2[i.first]; else ans+=Con2[i.first]; } } printf("%d\n",ans); } return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 364 KB | Output is correct |
2 | Correct | 1 ms | 364 KB | Output is correct |
3 | Correct | 1 ms | 364 KB | Output is correct |
4 | Correct | 1 ms | 364 KB | Output is correct |
5 | Correct | 1 ms | 364 KB | Output is correct |
6 | Correct | 1 ms | 364 KB | Output is correct |
7 | Correct | 1 ms | 364 KB | Output is correct |
8 | Correct | 1 ms | 364 KB | Output is correct |
9 | Correct | 1 ms | 364 KB | Output is correct |
10 | Correct | 1 ms | 364 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 364 KB | Output is correct |
2 | Correct | 1 ms | 364 KB | Output is correct |
3 | Correct | 1 ms | 364 KB | Output is correct |
4 | Correct | 1 ms | 364 KB | Output is correct |
5 | Correct | 1 ms | 364 KB | Output is correct |
6 | Correct | 1 ms | 364 KB | Output is correct |
7 | Correct | 1 ms | 364 KB | Output is correct |
8 | Correct | 1 ms | 364 KB | Output is correct |
9 | Correct | 1 ms | 364 KB | Output is correct |
10 | Correct | 1 ms | 364 KB | Output is correct |
11 | Correct | 318 ms | 4460 KB | Output is correct |
12 | Correct | 352 ms | 4192 KB | Output is correct |
13 | Correct | 422 ms | 3308 KB | Output is correct |
14 | Correct | 457 ms | 3432 KB | Output is correct |
15 | Correct | 415 ms | 4448 KB | Output is correct |
16 | Correct | 493 ms | 3564 KB | Output is correct |
17 | Correct | 468 ms | 3948 KB | Output is correct |
18 | Correct | 278 ms | 5356 KB | Output is correct |
19 | Correct | 323 ms | 2540 KB | Output is correct |
20 | Correct | 370 ms | 4188 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 364 KB | Output is correct |
2 | Correct | 1 ms | 364 KB | Output is correct |
3 | Correct | 1 ms | 364 KB | Output is correct |
4 | Correct | 1 ms | 364 KB | Output is correct |
5 | Correct | 1 ms | 364 KB | Output is correct |
6 | Correct | 1 ms | 364 KB | Output is correct |
7 | Correct | 1 ms | 364 KB | Output is correct |
8 | Correct | 1 ms | 364 KB | Output is correct |
9 | Correct | 1 ms | 364 KB | Output is correct |
10 | Correct | 1 ms | 364 KB | Output is correct |
11 | Correct | 318 ms | 4460 KB | Output is correct |
12 | Correct | 352 ms | 4192 KB | Output is correct |
13 | Correct | 422 ms | 3308 KB | Output is correct |
14 | Correct | 457 ms | 3432 KB | Output is correct |
15 | Correct | 415 ms | 4448 KB | Output is correct |
16 | Correct | 493 ms | 3564 KB | Output is correct |
17 | Correct | 468 ms | 3948 KB | Output is correct |
18 | Correct | 278 ms | 5356 KB | Output is correct |
19 | Correct | 323 ms | 2540 KB | Output is correct |
20 | Correct | 370 ms | 4188 KB | Output is correct |
21 | Correct | 400 ms | 4728 KB | Output is correct |
22 | Correct | 420 ms | 4716 KB | Output is correct |
23 | Correct | 525 ms | 3820 KB | Output is correct |
24 | Correct | 660 ms | 3856 KB | Output is correct |
25 | Correct | 468 ms | 5664 KB | Output is correct |
26 | Correct | 620 ms | 4096 KB | Output is correct |
27 | Correct | 572 ms | 4076 KB | Output is correct |
28 | Correct | 279 ms | 6636 KB | Output is correct |
29 | Correct | 361 ms | 2656 KB | Output is correct |
30 | Correct | 422 ms | 4868 KB | Output is correct |
31 | Correct | 538 ms | 4844 KB | Output is correct |
32 | Correct | 737 ms | 4716 KB | Output is correct |
33 | Correct | 443 ms | 3564 KB | Output is correct |
34 | Correct | 602 ms | 3692 KB | Output is correct |
35 | Correct | 579 ms | 4332 KB | Output is correct |
36 | Correct | 297 ms | 2540 KB | Output is correct |
37 | Correct | 370 ms | 4588 KB | Output is correct |
38 | Correct | 393 ms | 2856 KB | Output is correct |
39 | Correct | 518 ms | 3948 KB | Output is correct |
40 | Correct | 646 ms | 3692 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 364 KB | Output is correct |
2 | Correct | 1 ms | 364 KB | Output is correct |
3 | Correct | 1 ms | 364 KB | Output is correct |
4 | Correct | 1 ms | 364 KB | Output is correct |
5 | Correct | 1 ms | 364 KB | Output is correct |
6 | Correct | 1 ms | 364 KB | Output is correct |
7 | Correct | 1 ms | 364 KB | Output is correct |
8 | Correct | 1 ms | 364 KB | Output is correct |
9 | Correct | 1 ms | 364 KB | Output is correct |
10 | Correct | 1 ms | 364 KB | Output is correct |
11 | Correct | 87 ms | 26220 KB | Output is correct |
12 | Correct | 90 ms | 26348 KB | Output is correct |
13 | Correct | 105 ms | 26220 KB | Output is correct |
14 | Correct | 147 ms | 26220 KB | Output is correct |
15 | Correct | 92 ms | 26348 KB | Output is correct |
16 | Correct | 139 ms | 26220 KB | Output is correct |
17 | Correct | 125 ms | 26220 KB | Output is correct |
18 | Correct | 73 ms | 26348 KB | Output is correct |
19 | Correct | 86 ms | 26092 KB | Output is correct |
20 | Correct | 90 ms | 26220 KB | Output is correct |
21 | Correct | 109 ms | 26220 KB | Output is correct |
22 | Correct | 149 ms | 26220 KB | Output is correct |
23 | Correct | 89 ms | 26220 KB | Output is correct |
24 | Correct | 130 ms | 26220 KB | Output is correct |
25 | Correct | 126 ms | 26220 KB | Output is correct |
26 | Correct | 87 ms | 26092 KB | Output is correct |
27 | Correct | 110 ms | 26220 KB | Output is correct |
28 | Correct | 90 ms | 26092 KB | Output is correct |
29 | Correct | 108 ms | 26220 KB | Output is correct |
30 | Correct | 137 ms | 26220 KB | Output is correct |
31 | Correct | 89 ms | 26092 KB | Output is correct |
32 | Correct | 140 ms | 26220 KB | Output is correct |
33 | Correct | 129 ms | 26220 KB | Output is correct |
34 | Correct | 76 ms | 26112 KB | Output is correct |
35 | Correct | 109 ms | 26160 KB | Output is correct |
36 | Correct | 120 ms | 26220 KB | Output is correct |
37 | Correct | 110 ms | 26220 KB | Output is correct |
38 | Correct | 108 ms | 26220 KB | Output is correct |
39 | Correct | 114 ms | 26220 KB | Output is correct |
40 | Correct | 113 ms | 26220 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 364 KB | Output is correct |
2 | Correct | 1 ms | 364 KB | Output is correct |
3 | Correct | 1 ms | 364 KB | Output is correct |
4 | Correct | 1 ms | 364 KB | Output is correct |
5 | Correct | 1 ms | 364 KB | Output is correct |
6 | Correct | 1 ms | 364 KB | Output is correct |
7 | Correct | 1 ms | 364 KB | Output is correct |
8 | Correct | 1 ms | 364 KB | Output is correct |
9 | Correct | 1 ms | 364 KB | Output is correct |
10 | Correct | 1 ms | 364 KB | Output is correct |
11 | Correct | 318 ms | 4460 KB | Output is correct |
12 | Correct | 352 ms | 4192 KB | Output is correct |
13 | Correct | 422 ms | 3308 KB | Output is correct |
14 | Correct | 457 ms | 3432 KB | Output is correct |
15 | Correct | 415 ms | 4448 KB | Output is correct |
16 | Correct | 493 ms | 3564 KB | Output is correct |
17 | Correct | 468 ms | 3948 KB | Output is correct |
18 | Correct | 278 ms | 5356 KB | Output is correct |
19 | Correct | 323 ms | 2540 KB | Output is correct |
20 | Correct | 370 ms | 4188 KB | Output is correct |
21 | Correct | 400 ms | 4728 KB | Output is correct |
22 | Correct | 420 ms | 4716 KB | Output is correct |
23 | Correct | 525 ms | 3820 KB | Output is correct |
24 | Correct | 660 ms | 3856 KB | Output is correct |
25 | Correct | 468 ms | 5664 KB | Output is correct |
26 | Correct | 620 ms | 4096 KB | Output is correct |
27 | Correct | 572 ms | 4076 KB | Output is correct |
28 | Correct | 279 ms | 6636 KB | Output is correct |
29 | Correct | 361 ms | 2656 KB | Output is correct |
30 | Correct | 422 ms | 4868 KB | Output is correct |
31 | Correct | 538 ms | 4844 KB | Output is correct |
32 | Correct | 737 ms | 4716 KB | Output is correct |
33 | Correct | 443 ms | 3564 KB | Output is correct |
34 | Correct | 602 ms | 3692 KB | Output is correct |
35 | Correct | 579 ms | 4332 KB | Output is correct |
36 | Correct | 297 ms | 2540 KB | Output is correct |
37 | Correct | 370 ms | 4588 KB | Output is correct |
38 | Correct | 393 ms | 2856 KB | Output is correct |
39 | Correct | 518 ms | 3948 KB | Output is correct |
40 | Correct | 646 ms | 3692 KB | Output is correct |
41 | Correct | 87 ms | 26220 KB | Output is correct |
42 | Correct | 90 ms | 26348 KB | Output is correct |
43 | Correct | 105 ms | 26220 KB | Output is correct |
44 | Correct | 147 ms | 26220 KB | Output is correct |
45 | Correct | 92 ms | 26348 KB | Output is correct |
46 | Correct | 139 ms | 26220 KB | Output is correct |
47 | Correct | 125 ms | 26220 KB | Output is correct |
48 | Correct | 73 ms | 26348 KB | Output is correct |
49 | Correct | 86 ms | 26092 KB | Output is correct |
50 | Correct | 90 ms | 26220 KB | Output is correct |
51 | Correct | 109 ms | 26220 KB | Output is correct |
52 | Correct | 149 ms | 26220 KB | Output is correct |
53 | Correct | 89 ms | 26220 KB | Output is correct |
54 | Correct | 130 ms | 26220 KB | Output is correct |
55 | Correct | 126 ms | 26220 KB | Output is correct |
56 | Correct | 87 ms | 26092 KB | Output is correct |
57 | Correct | 110 ms | 26220 KB | Output is correct |
58 | Correct | 90 ms | 26092 KB | Output is correct |
59 | Correct | 108 ms | 26220 KB | Output is correct |
60 | Correct | 137 ms | 26220 KB | Output is correct |
61 | Correct | 89 ms | 26092 KB | Output is correct |
62 | Correct | 140 ms | 26220 KB | Output is correct |
63 | Correct | 129 ms | 26220 KB | Output is correct |
64 | Correct | 76 ms | 26112 KB | Output is correct |
65 | Correct | 109 ms | 26160 KB | Output is correct |
66 | Correct | 120 ms | 26220 KB | Output is correct |
67 | Correct | 110 ms | 26220 KB | Output is correct |
68 | Correct | 108 ms | 26220 KB | Output is correct |
69 | Correct | 114 ms | 26220 KB | Output is correct |
70 | Correct | 113 ms | 26220 KB | Output is correct |
71 | Correct | 684 ms | 31120 KB | Output is correct |
72 | Correct | 730 ms | 31340 KB | Output is correct |
73 | Correct | 1000 ms | 29804 KB | Output is correct |
74 | Correct | 1860 ms | 30124 KB | Output is correct |
75 | Correct | 772 ms | 53612 KB | Output is correct |
76 | Correct | 1628 ms | 52032 KB | Output is correct |
77 | Correct | 1326 ms | 51948 KB | Output is correct |
78 | Correct | 412 ms | 55660 KB | Output is correct |
79 | Correct | 643 ms | 49656 KB | Output is correct |
80 | Correct | 713 ms | 52740 KB | Output is correct |
81 | Correct | 1097 ms | 52588 KB | Output is correct |
82 | Correct | 1955 ms | 51828 KB | Output is correct |
83 | Correct | 719 ms | 51136 KB | Output is correct |
84 | Correct | 1569 ms | 51580 KB | Output is correct |
85 | Correct | 1362 ms | 51948 KB | Output is correct |
86 | Correct | 418 ms | 49516 KB | Output is correct |
87 | Correct | 681 ms | 52716 KB | Output is correct |
88 | Correct | 650 ms | 49516 KB | Output is correct |
89 | Correct | 1000 ms | 51252 KB | Output is correct |
90 | Correct | 1593 ms | 51688 KB | Output is correct |
91 | Correct | 713 ms | 50924 KB | Output is correct |
92 | Correct | 1611 ms | 52008 KB | Output is correct |
93 | Correct | 1339 ms | 51872 KB | Output is correct |
94 | Correct | 407 ms | 49568 KB | Output is correct |
95 | Correct | 1112 ms | 51864 KB | Output is correct |
96 | Correct | 1130 ms | 48164 KB | Output is correct |
97 | Correct | 1115 ms | 51692 KB | Output is correct |
98 | Correct | 1112 ms | 51948 KB | Output is correct |
99 | Correct | 1102 ms | 51884 KB | Output is correct |
100 | Correct | 1109 ms | 51820 KB | Output is correct |