Submission #705579

# Submission time Handle Problem Language Result Execution time Memory
705579 2023-03-04T17:07:54 Z rainboy Snake Escaping (JOI18_snake_escaping) C
100 / 100
1932 ms 46568 KB
#include <stdio.h>

#define N	20
#define M	12
#define L	8
#define Q	1000000
#define N_	531441

int min(int a, int b) { return a < b ? a : b; }

int pp3[M + 1];

void init() {
	int m;

	pp3[0] = 1;
	for (m = 1; m <= M; m++)
		pp3[m] = pp3[m - 1] * 3;
}

void solve(char *cc, int *dp, int m) {
	int p, i;

	if (m == 0) {
		dp[0] = cc[0] - '0';
		return;
	}
	p = pp3[m - 1];
	solve(cc, dp, m - 1);
	solve(cc + (1 << m - 1), dp + p, m - 1);
	for (i = 0; i < p; i++)
		dp[p * 2 + i] = dp[i] + dp[p + i];
}

int main() {
	static char cc[1 << N];
	static int bb_[Q], lower[Q], upper[Q], ans[Q], dp[N_];
	int n, m, l, q, h, i, b;

	init();
	scanf("%d%d%s", &n, &q, cc), m = min(n, M), l = n - m;
	for (h = 0; h < q; h++) {
		static char s[N + 1];

		scanf("%s", s);
		for (i = m - 1; i >= 0; i--)
			bb_[h] = bb_[h] * 3 + (s[n - 1 - i] == '?' ? 2 : (s[n - 1 - i] == '0' ? 0 : 1));
		for (i = 0; i < l; i++)
			if (s[n - 1 - m - i] == '1')
				lower[h] |= 1 << i, upper[h] |= 1 << i;
			else if (s[n - 1 - m - i] == '?')
				upper[h] |= 1 << i;
	}
	for (b = 0; b < 1 << l; b++) {
		solve(cc + (b << m), dp, m);
		for (h = 0; h < q; h++)
			if ((lower[h] & b) == lower[h] && (upper[h] | b) == upper[h])
				ans[h] += dp[bb_[h]];
	}
	for (h = 0; h < q; h++)
		printf("%d\n", ans[h]);
	return 0;
}

Compilation message

snake_escaping.c: In function 'solve':
snake_escaping.c:30:21: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
   30 |  solve(cc + (1 << m - 1), dp + p, m - 1);
      |                   ~~^~~
snake_escaping.c: In function 'main':
snake_escaping.c:41:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   41 |  scanf("%d%d%s", &n, &q, cc), m = min(n, M), l = n - m;
      |  ^~~~~~~~~~~~~~~~~~~~~~~~~~~
snake_escaping.c:45:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   45 |   scanf("%s", s);
      |   ^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 1 ms 552 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 1 ms 556 KB Output is correct
10 Correct 1 ms 556 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 1 ms 552 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 1 ms 556 KB Output is correct
10 Correct 1 ms 556 KB Output is correct
11 Correct 207 ms 23008 KB Output is correct
12 Correct 222 ms 22708 KB Output is correct
13 Correct 200 ms 21936 KB Output is correct
14 Correct 195 ms 22076 KB Output is correct
15 Correct 202 ms 23116 KB Output is correct
16 Correct 210 ms 22220 KB Output is correct
17 Correct 207 ms 22224 KB Output is correct
18 Correct 167 ms 24012 KB Output is correct
19 Correct 164 ms 20988 KB Output is correct
20 Correct 225 ms 22740 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 1 ms 552 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 1 ms 556 KB Output is correct
10 Correct 1 ms 556 KB Output is correct
11 Correct 207 ms 23008 KB Output is correct
12 Correct 222 ms 22708 KB Output is correct
13 Correct 200 ms 21936 KB Output is correct
14 Correct 195 ms 22076 KB Output is correct
15 Correct 202 ms 23116 KB Output is correct
16 Correct 210 ms 22220 KB Output is correct
17 Correct 207 ms 22224 KB Output is correct
18 Correct 167 ms 24012 KB Output is correct
19 Correct 164 ms 20988 KB Output is correct
20 Correct 225 ms 22740 KB Output is correct
21 Correct 249 ms 35660 KB Output is correct
22 Correct 264 ms 31876 KB Output is correct
23 Correct 234 ms 34840 KB Output is correct
24 Correct 230 ms 34744 KB Output is correct
25 Correct 241 ms 36664 KB Output is correct
26 Correct 250 ms 33580 KB Output is correct
27 Correct 255 ms 35148 KB Output is correct
28 Correct 205 ms 33304 KB Output is correct
29 Correct 207 ms 33760 KB Output is correct
30 Correct 257 ms 33672 KB Output is correct
31 Correct 245 ms 33064 KB Output is correct
32 Correct 252 ms 32688 KB Output is correct
33 Correct 225 ms 33192 KB Output is correct
34 Correct 230 ms 34632 KB Output is correct
35 Correct 255 ms 33432 KB Output is correct
36 Correct 190 ms 30532 KB Output is correct
37 Correct 240 ms 27604 KB Output is correct
38 Correct 210 ms 30580 KB Output is correct
39 Correct 239 ms 33780 KB Output is correct
40 Correct 238 ms 30340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 1 ms 552 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 1 ms 556 KB Output is correct
10 Correct 1 ms 556 KB Output is correct
11 Correct 114 ms 6488 KB Output is correct
12 Correct 118 ms 6252 KB Output is correct
13 Correct 143 ms 6356 KB Output is correct
14 Correct 136 ms 6348 KB Output is correct
15 Correct 169 ms 6504 KB Output is correct
16 Correct 133 ms 6360 KB Output is correct
17 Correct 135 ms 6428 KB Output is correct
18 Correct 103 ms 6416 KB Output is correct
19 Correct 118 ms 6296 KB Output is correct
20 Correct 116 ms 6484 KB Output is correct
21 Correct 152 ms 6392 KB Output is correct
22 Correct 126 ms 6376 KB Output is correct
23 Correct 115 ms 6352 KB Output is correct
24 Correct 129 ms 6388 KB Output is correct
25 Correct 138 ms 6316 KB Output is correct
26 Correct 97 ms 6344 KB Output is correct
27 Correct 120 ms 6288 KB Output is correct
28 Correct 114 ms 6328 KB Output is correct
29 Correct 115 ms 6356 KB Output is correct
30 Correct 131 ms 6400 KB Output is correct
31 Correct 153 ms 6364 KB Output is correct
32 Correct 142 ms 6356 KB Output is correct
33 Correct 134 ms 6356 KB Output is correct
34 Correct 103 ms 5968 KB Output is correct
35 Correct 157 ms 6364 KB Output is correct
36 Correct 154 ms 6348 KB Output is correct
37 Correct 153 ms 6360 KB Output is correct
38 Correct 162 ms 6348 KB Output is correct
39 Correct 153 ms 6460 KB Output is correct
40 Correct 152 ms 6328 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 1 ms 552 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 468 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 1 ms 556 KB Output is correct
10 Correct 1 ms 556 KB Output is correct
11 Correct 207 ms 23008 KB Output is correct
12 Correct 222 ms 22708 KB Output is correct
13 Correct 200 ms 21936 KB Output is correct
14 Correct 195 ms 22076 KB Output is correct
15 Correct 202 ms 23116 KB Output is correct
16 Correct 210 ms 22220 KB Output is correct
17 Correct 207 ms 22224 KB Output is correct
18 Correct 167 ms 24012 KB Output is correct
19 Correct 164 ms 20988 KB Output is correct
20 Correct 225 ms 22740 KB Output is correct
21 Correct 249 ms 35660 KB Output is correct
22 Correct 264 ms 31876 KB Output is correct
23 Correct 234 ms 34840 KB Output is correct
24 Correct 230 ms 34744 KB Output is correct
25 Correct 241 ms 36664 KB Output is correct
26 Correct 250 ms 33580 KB Output is correct
27 Correct 255 ms 35148 KB Output is correct
28 Correct 205 ms 33304 KB Output is correct
29 Correct 207 ms 33760 KB Output is correct
30 Correct 257 ms 33672 KB Output is correct
31 Correct 245 ms 33064 KB Output is correct
32 Correct 252 ms 32688 KB Output is correct
33 Correct 225 ms 33192 KB Output is correct
34 Correct 230 ms 34632 KB Output is correct
35 Correct 255 ms 33432 KB Output is correct
36 Correct 190 ms 30532 KB Output is correct
37 Correct 240 ms 27604 KB Output is correct
38 Correct 210 ms 30580 KB Output is correct
39 Correct 239 ms 33780 KB Output is correct
40 Correct 238 ms 30340 KB Output is correct
41 Correct 114 ms 6488 KB Output is correct
42 Correct 118 ms 6252 KB Output is correct
43 Correct 143 ms 6356 KB Output is correct
44 Correct 136 ms 6348 KB Output is correct
45 Correct 169 ms 6504 KB Output is correct
46 Correct 133 ms 6360 KB Output is correct
47 Correct 135 ms 6428 KB Output is correct
48 Correct 103 ms 6416 KB Output is correct
49 Correct 118 ms 6296 KB Output is correct
50 Correct 116 ms 6484 KB Output is correct
51 Correct 152 ms 6392 KB Output is correct
52 Correct 126 ms 6376 KB Output is correct
53 Correct 115 ms 6352 KB Output is correct
54 Correct 129 ms 6388 KB Output is correct
55 Correct 138 ms 6316 KB Output is correct
56 Correct 97 ms 6344 KB Output is correct
57 Correct 120 ms 6288 KB Output is correct
58 Correct 114 ms 6328 KB Output is correct
59 Correct 115 ms 6356 KB Output is correct
60 Correct 131 ms 6400 KB Output is correct
61 Correct 153 ms 6364 KB Output is correct
62 Correct 142 ms 6356 KB Output is correct
63 Correct 134 ms 6356 KB Output is correct
64 Correct 103 ms 5968 KB Output is correct
65 Correct 157 ms 6364 KB Output is correct
66 Correct 154 ms 6348 KB Output is correct
67 Correct 153 ms 6360 KB Output is correct
68 Correct 162 ms 6348 KB Output is correct
69 Correct 153 ms 6460 KB Output is correct
70 Correct 152 ms 6328 KB Output is correct
71 Correct 859 ms 44252 KB Output is correct
72 Correct 942 ms 41772 KB Output is correct
73 Correct 1407 ms 44184 KB Output is correct
74 Correct 1248 ms 44624 KB Output is correct
75 Correct 1932 ms 46568 KB Output is correct
76 Correct 1298 ms 44528 KB Output is correct
77 Correct 1297 ms 42568 KB Output is correct
78 Correct 614 ms 42156 KB Output is correct
79 Correct 803 ms 42508 KB Output is correct
80 Correct 892 ms 44236 KB Output is correct
81 Correct 1561 ms 42996 KB Output is correct
82 Correct 1152 ms 44468 KB Output is correct
83 Correct 728 ms 42208 KB Output is correct
84 Correct 1204 ms 43752 KB Output is correct
85 Correct 1293 ms 41168 KB Output is correct
86 Correct 459 ms 36748 KB Output is correct
87 Correct 895 ms 38476 KB Output is correct
88 Correct 829 ms 35664 KB Output is correct
89 Correct 932 ms 37240 KB Output is correct
90 Correct 1151 ms 44224 KB Output is correct
91 Correct 1532 ms 43720 KB Output is correct
92 Correct 1309 ms 42092 KB Output is correct
93 Correct 1274 ms 36260 KB Output is correct
94 Correct 562 ms 30632 KB Output is correct
95 Correct 1614 ms 41856 KB Output is correct
96 Correct 1616 ms 42348 KB Output is correct
97 Correct 1625 ms 37152 KB Output is correct
98 Correct 1620 ms 35340 KB Output is correct
99 Correct 1607 ms 36908 KB Output is correct
100 Correct 1598 ms 42640 KB Output is correct