답안 #160135

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
160135 2019-10-26T06:39:39 Z GioChkhaidze Snake Escaping (JOI18_snake_escaping) C++14
75 / 100
791 ms 65540 KB
#pragma GCC optimize ("O3")
#pragma GCC optimize ("Ofast")
#include <bits/stdc++.h>
using namespace std;
const int Q=1e6+5;
const int M20=1048576;
const int M13=1594323;
int n,q,C[M20+5],M[15],dp[M13+5],ANS[Q],Y[Q],Last2[M13+5],x,ko,K,i,j,k,Mid;	
bool Bo[Q][(1<<7)+5];
string S,s;
char c;
main () { 
	ios::sync_with_stdio(false);
	cin>>n>>q;
	
	M[0]=1;
	for (int i=1; i<=13; i++) 
		M[i]=M[i-1]*3;
	
	Mid=13;
	
	if (n<=Mid) {	
		for (i=0; i<(1<<n); i++) {
			cin>>c;
			C[i]=c-'0';
			
			x=0;
			for (j=0; j<n; j++) 
				if (i&(1<<j)) x+=M[j];
			dp[x]+=C[i];
		}
		
		for (i=0; i<M[n]; i++) {
			x=i;
			for (j=n-1; j>=0; j--) 
				if (x>=2*M[j]) x-=2*M[j],dp[i]=(dp[i-2*M[j]]+dp[i-M[j]]);	
					else
				if (x>=M[j]) x-=M[j];
		}
		
		for (i=1; i<=q; i++) {
			x=0;
			cin>>s;			
			for (j=0; j<s.size(); j++) 
				if (s[s.size()-j-1]=='?') x+=2*M[j];	
					else
				if (s[s.size()-j-1]=='1') x+=M[j];
			printf("%d\n",dp[x]);
		}
	}
		else {
		for (i=0; i<(1<<n); i++) {
			cin>>c;
			C[i]=c-'0';
		}

		K=(n-Mid);
		
		for (i=1; i<=q; i++) {
			cin>>S;	
			
			for (k=S.size()-1; k>=K; k--) {
				if (S[k]=='?') Y[i]+=2*M[S.size()-1-k];	
					else
				if (S[k]=='1') Y[i]+=M[S.size()-1-k];
			}
	
			for (j=0; j<(1<<K); j++) {
				ko=0;
				for (k=0; k<K; k++)
					if ((S[K-k-1]=='1' && (!((1<<k)&j))) ||
					    (S[K-k-1]=='0' && (((1<<k)&j)))) { ko=1; break; }
					    
				Bo[i][j]=(!ko);	    
			}
		}
		
		for (i=0; i<M[Mid]; i++) {
			x=i;
			Last2[i]=-1;
			for (j=Mid-1; j>=0; j--) 
				if (x>=2*M[j]) { Last2[i]=j; break; }
						else
				if (x>=M[j]) x-=M[j];
		}
		
		for (i=0; i<(1<<K); i++) {
			for (int j=0; j<M[Mid]; j++)
				dp[j]=0;

			for (j=0; j<(1<<Mid); j++) {
				x=0;
				for (int k=0; k<Mid; k++) 
					if (j&(1<<k)) x+=M[k];
				dp[x]=C[i*(1<<Mid)+j];
			}
			
			for (j=0; j<M[Mid]; j++) {
				x=j;
				if (Last2[j]==-1) continue;
				dp[j]=(dp[j-2*M[Last2[j]]]+dp[j-M[Last2[j]]]);	
			}
			
			for (j=1; j<=q; j++) {
				if (!Bo[j][i]) continue;
				ANS[j]+=dp[Y[j]];
			}
		}
		
		for (i=1; i<=q; i++) 
			printf("%d\n",ANS[i]);		
	}
}

Compilation message

snake_escaping.cpp:12:7: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main () { 
       ^
snake_escaping.cpp: In function 'int main()':
snake_escaping.cpp:44:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    for (j=0; j<s.size(); j++) 
              ~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 632 KB Output is correct
2 Correct 5 ms 632 KB Output is correct
3 Correct 4 ms 632 KB Output is correct
4 Correct 5 ms 632 KB Output is correct
5 Correct 5 ms 636 KB Output is correct
6 Correct 4 ms 632 KB Output is correct
7 Correct 5 ms 632 KB Output is correct
8 Correct 7 ms 632 KB Output is correct
9 Correct 5 ms 632 KB Output is correct
10 Correct 5 ms 632 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 632 KB Output is correct
2 Correct 5 ms 632 KB Output is correct
3 Correct 4 ms 632 KB Output is correct
4 Correct 5 ms 632 KB Output is correct
5 Correct 5 ms 636 KB Output is correct
6 Correct 4 ms 632 KB Output is correct
7 Correct 5 ms 632 KB Output is correct
8 Correct 7 ms 632 KB Output is correct
9 Correct 5 ms 632 KB Output is correct
10 Correct 5 ms 632 KB Output is correct
11 Correct 255 ms 4632 KB Output is correct
12 Correct 281 ms 4268 KB Output is correct
13 Correct 282 ms 3536 KB Output is correct
14 Correct 285 ms 3704 KB Output is correct
15 Correct 283 ms 4728 KB Output is correct
16 Correct 298 ms 3832 KB Output is correct
17 Correct 306 ms 3796 KB Output is correct
18 Correct 218 ms 5624 KB Output is correct
19 Correct 258 ms 2752 KB Output is correct
20 Correct 270 ms 4344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 632 KB Output is correct
2 Correct 5 ms 632 KB Output is correct
3 Correct 4 ms 632 KB Output is correct
4 Correct 5 ms 632 KB Output is correct
5 Correct 5 ms 636 KB Output is correct
6 Correct 4 ms 632 KB Output is correct
7 Correct 5 ms 632 KB Output is correct
8 Correct 7 ms 632 KB Output is correct
9 Correct 5 ms 632 KB Output is correct
10 Correct 5 ms 632 KB Output is correct
11 Correct 255 ms 4632 KB Output is correct
12 Correct 281 ms 4268 KB Output is correct
13 Correct 282 ms 3536 KB Output is correct
14 Correct 285 ms 3704 KB Output is correct
15 Correct 283 ms 4728 KB Output is correct
16 Correct 298 ms 3832 KB Output is correct
17 Correct 306 ms 3796 KB Output is correct
18 Correct 218 ms 5624 KB Output is correct
19 Correct 258 ms 2752 KB Output is correct
20 Correct 270 ms 4344 KB Output is correct
21 Correct 351 ms 10732 KB Output is correct
22 Correct 374 ms 10852 KB Output is correct
23 Correct 445 ms 9976 KB Output is correct
24 Correct 450 ms 9720 KB Output is correct
25 Correct 417 ms 11728 KB Output is correct
26 Correct 475 ms 10332 KB Output is correct
27 Correct 488 ms 10104 KB Output is correct
28 Correct 293 ms 12636 KB Output is correct
29 Correct 358 ms 8824 KB Output is correct
30 Correct 380 ms 10844 KB Output is correct
31 Correct 453 ms 10648 KB Output is correct
32 Correct 532 ms 10872 KB Output is correct
33 Correct 394 ms 9624 KB Output is correct
34 Correct 472 ms 9692 KB Output is correct
35 Correct 497 ms 10104 KB Output is correct
36 Correct 291 ms 8732 KB Output is correct
37 Correct 358 ms 10616 KB Output is correct
38 Correct 364 ms 8696 KB Output is correct
39 Correct 459 ms 9832 KB Output is correct
40 Correct 478 ms 9720 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 632 KB Output is correct
2 Correct 5 ms 632 KB Output is correct
3 Correct 4 ms 632 KB Output is correct
4 Correct 5 ms 632 KB Output is correct
5 Correct 5 ms 636 KB Output is correct
6 Correct 4 ms 632 KB Output is correct
7 Correct 5 ms 632 KB Output is correct
8 Correct 7 ms 632 KB Output is correct
9 Correct 5 ms 632 KB Output is correct
10 Correct 5 ms 632 KB Output is correct
11 Correct 791 ms 24056 KB Output is correct
12 Correct 694 ms 24072 KB Output is correct
13 Correct 687 ms 24056 KB Output is correct
14 Correct 691 ms 24028 KB Output is correct
15 Correct 729 ms 24184 KB Output is correct
16 Correct 713 ms 24184 KB Output is correct
17 Correct 686 ms 24088 KB Output is correct
18 Correct 721 ms 24312 KB Output is correct
19 Correct 671 ms 23928 KB Output is correct
20 Correct 680 ms 24056 KB Output is correct
21 Correct 719 ms 24184 KB Output is correct
22 Correct 707 ms 24056 KB Output is correct
23 Correct 714 ms 24056 KB Output is correct
24 Correct 737 ms 24056 KB Output is correct
25 Correct 723 ms 24036 KB Output is correct
26 Correct 659 ms 23912 KB Output is correct
27 Correct 682 ms 24184 KB Output is correct
28 Correct 662 ms 23928 KB Output is correct
29 Correct 695 ms 24056 KB Output is correct
30 Correct 703 ms 24056 KB Output is correct
31 Correct 684 ms 24192 KB Output is correct
32 Correct 698 ms 24184 KB Output is correct
33 Correct 689 ms 24056 KB Output is correct
34 Correct 650 ms 23856 KB Output is correct
35 Correct 700 ms 24164 KB Output is correct
36 Correct 677 ms 24056 KB Output is correct
37 Correct 682 ms 24056 KB Output is correct
38 Correct 663 ms 24056 KB Output is correct
39 Correct 745 ms 24056 KB Output is correct
40 Correct 692 ms 24020 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 632 KB Output is correct
2 Correct 5 ms 632 KB Output is correct
3 Correct 4 ms 632 KB Output is correct
4 Correct 5 ms 632 KB Output is correct
5 Correct 5 ms 636 KB Output is correct
6 Correct 4 ms 632 KB Output is correct
7 Correct 5 ms 632 KB Output is correct
8 Correct 7 ms 632 KB Output is correct
9 Correct 5 ms 632 KB Output is correct
10 Correct 5 ms 632 KB Output is correct
11 Correct 255 ms 4632 KB Output is correct
12 Correct 281 ms 4268 KB Output is correct
13 Correct 282 ms 3536 KB Output is correct
14 Correct 285 ms 3704 KB Output is correct
15 Correct 283 ms 4728 KB Output is correct
16 Correct 298 ms 3832 KB Output is correct
17 Correct 306 ms 3796 KB Output is correct
18 Correct 218 ms 5624 KB Output is correct
19 Correct 258 ms 2752 KB Output is correct
20 Correct 270 ms 4344 KB Output is correct
21 Correct 351 ms 10732 KB Output is correct
22 Correct 374 ms 10852 KB Output is correct
23 Correct 445 ms 9976 KB Output is correct
24 Correct 450 ms 9720 KB Output is correct
25 Correct 417 ms 11728 KB Output is correct
26 Correct 475 ms 10332 KB Output is correct
27 Correct 488 ms 10104 KB Output is correct
28 Correct 293 ms 12636 KB Output is correct
29 Correct 358 ms 8824 KB Output is correct
30 Correct 380 ms 10844 KB Output is correct
31 Correct 453 ms 10648 KB Output is correct
32 Correct 532 ms 10872 KB Output is correct
33 Correct 394 ms 9624 KB Output is correct
34 Correct 472 ms 9692 KB Output is correct
35 Correct 497 ms 10104 KB Output is correct
36 Correct 291 ms 8732 KB Output is correct
37 Correct 358 ms 10616 KB Output is correct
38 Correct 364 ms 8696 KB Output is correct
39 Correct 459 ms 9832 KB Output is correct
40 Correct 478 ms 9720 KB Output is correct
41 Correct 791 ms 24056 KB Output is correct
42 Correct 694 ms 24072 KB Output is correct
43 Correct 687 ms 24056 KB Output is correct
44 Correct 691 ms 24028 KB Output is correct
45 Correct 729 ms 24184 KB Output is correct
46 Correct 713 ms 24184 KB Output is correct
47 Correct 686 ms 24088 KB Output is correct
48 Correct 721 ms 24312 KB Output is correct
49 Correct 671 ms 23928 KB Output is correct
50 Correct 680 ms 24056 KB Output is correct
51 Correct 719 ms 24184 KB Output is correct
52 Correct 707 ms 24056 KB Output is correct
53 Correct 714 ms 24056 KB Output is correct
54 Correct 737 ms 24056 KB Output is correct
55 Correct 723 ms 24036 KB Output is correct
56 Correct 659 ms 23912 KB Output is correct
57 Correct 682 ms 24184 KB Output is correct
58 Correct 662 ms 23928 KB Output is correct
59 Correct 695 ms 24056 KB Output is correct
60 Correct 703 ms 24056 KB Output is correct
61 Correct 684 ms 24192 KB Output is correct
62 Correct 698 ms 24184 KB Output is correct
63 Correct 689 ms 24056 KB Output is correct
64 Correct 650 ms 23856 KB Output is correct
65 Correct 700 ms 24164 KB Output is correct
66 Correct 677 ms 24056 KB Output is correct
67 Correct 682 ms 24056 KB Output is correct
68 Correct 663 ms 24056 KB Output is correct
69 Correct 745 ms 24056 KB Output is correct
70 Correct 692 ms 24020 KB Output is correct
71 Runtime error 682 ms 65540 KB Execution killed with signal 9 (could be triggered by violating memory limits)
72 Halted 0 ms 0 KB -