Submission #958752

# Submission time Handle Problem Language Result Execution time Memory
958752 2024-04-06T14:17:47 Z TAhmed33 Snake Escaping (JOI18_snake_escaping) C++
75 / 100
2000 ms 47608 KB
#include <bits/stdc++.h>
using namespace std;
const int B = 20;
int dp[2][1 << B], dq[2][1 << B], arr[1 << B];
int n, q;
int main () {
	cin >> n >> q;
	for (int i = 0; i < (1 << n); i++) {
		char s; cin >> s; int x = s - '0';
		arr[i] = x;
		dp[1][i] = dq[1][i] = x;
	}
	for (int i = 0, c = 0; i < n; i++, c ^= 1) {
		for (int j = 0; j < (1 << n); j++) {
			dp[c][j] = dp[c ^ 1][j];
			if (j & (1 << i)) dp[c][j] += dp[c ^ 1][j ^ (1 << i)];
			dq[c][j] = dq[c ^ 1][j];
			if (!(j & (1 << i))) dq[c][j] += dq[c ^ 1][j ^ (1 << i)];
		}
	}
	int ll = (n - 1) & 1;
	while (q--) {
		string s; cin >> s;
		int a = 0, b = 0, c = 0;
		for (int i = 0; i < n; i++) {
			if (s[i] == '0') {
				a ^= 1 << (n - i - 1);
			} else if (s[i] == '1') {
				b ^= 1 << (n - i - 1);
			} else {
				c ^= 1 << (n - i - 1);
			}
		}
		int ret = 0;
		if (__builtin_popcount(a) <= 6) {
			int m = a;
			while (true) {
				assert(0 <= m && m < (1 << n));
				if (__builtin_popcount(m) & 1) {
					ret -= dq[ll][b | m];
				} else {
					ret += dq[ll][b | m];
				}
				if (m == 0) break;
				m = (m - 1) & a;
			}
		} else if (__builtin_popcount(b) <= 6) {
			int m = b;
			while (true) {
				if (__builtin_popcount(m) & 1) {
					ret -= dp[ll][c | m];
				} else {
					ret += dp[ll][c | m];
				}
				if (m == 0) break;
				m = (m - 1) & b;
			} 
		} else {
			int m = c;
			while (true) {
				ret += arr[b ^ m];
				if (m == 0) break;
				m = (m - 1) & c;
			} 
		}
		cout << (ret < 0 ? -ret : ret) << '\n';
	}
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 8536 KB Output is correct
2 Correct 3 ms 8540 KB Output is correct
3 Correct 3 ms 8540 KB Output is correct
4 Correct 4 ms 8540 KB Output is correct
5 Correct 3 ms 8640 KB Output is correct
6 Correct 4 ms 8536 KB Output is correct
7 Correct 3 ms 8540 KB Output is correct
8 Correct 3 ms 8540 KB Output is correct
9 Correct 3 ms 8540 KB Output is correct
10 Correct 3 ms 8540 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 8536 KB Output is correct
2 Correct 3 ms 8540 KB Output is correct
3 Correct 3 ms 8540 KB Output is correct
4 Correct 4 ms 8540 KB Output is correct
5 Correct 3 ms 8640 KB Output is correct
6 Correct 4 ms 8536 KB Output is correct
7 Correct 3 ms 8540 KB Output is correct
8 Correct 3 ms 8540 KB Output is correct
9 Correct 3 ms 8540 KB Output is correct
10 Correct 3 ms 8540 KB Output is correct
11 Correct 1528 ms 23380 KB Output is correct
12 Correct 1596 ms 23024 KB Output is correct
13 Correct 1603 ms 22072 KB Output is correct
14 Correct 1547 ms 22356 KB Output is correct
15 Correct 1574 ms 23632 KB Output is correct
16 Correct 1542 ms 22524 KB Output is correct
17 Correct 1558 ms 22512 KB Output is correct
18 Correct 1469 ms 24220 KB Output is correct
19 Correct 1582 ms 21188 KB Output is correct
20 Correct 1553 ms 22972 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 8536 KB Output is correct
2 Correct 3 ms 8540 KB Output is correct
3 Correct 3 ms 8540 KB Output is correct
4 Correct 4 ms 8540 KB Output is correct
5 Correct 3 ms 8640 KB Output is correct
6 Correct 4 ms 8536 KB Output is correct
7 Correct 3 ms 8540 KB Output is correct
8 Correct 3 ms 8540 KB Output is correct
9 Correct 3 ms 8540 KB Output is correct
10 Correct 3 ms 8540 KB Output is correct
11 Correct 1528 ms 23380 KB Output is correct
12 Correct 1596 ms 23024 KB Output is correct
13 Correct 1603 ms 22072 KB Output is correct
14 Correct 1547 ms 22356 KB Output is correct
15 Correct 1574 ms 23632 KB Output is correct
16 Correct 1542 ms 22524 KB Output is correct
17 Correct 1558 ms 22512 KB Output is correct
18 Correct 1469 ms 24220 KB Output is correct
19 Correct 1582 ms 21188 KB Output is correct
20 Correct 1553 ms 22972 KB Output is correct
21 Correct 1582 ms 26272 KB Output is correct
22 Correct 1635 ms 26440 KB Output is correct
23 Correct 1834 ms 25416 KB Output is correct
24 Correct 1715 ms 25336 KB Output is correct
25 Correct 1570 ms 27500 KB Output is correct
26 Correct 1609 ms 26224 KB Output is correct
27 Correct 1660 ms 25824 KB Output is correct
28 Correct 1479 ms 28148 KB Output is correct
29 Correct 1738 ms 24352 KB Output is correct
30 Correct 1539 ms 26300 KB Output is correct
31 Correct 1604 ms 26260 KB Output is correct
32 Correct 1645 ms 26332 KB Output is correct
33 Correct 1563 ms 25392 KB Output is correct
34 Correct 1642 ms 25388 KB Output is correct
35 Correct 1642 ms 25812 KB Output is correct
36 Correct 1486 ms 24144 KB Output is correct
37 Correct 1522 ms 26336 KB Output is correct
38 Correct 1676 ms 24156 KB Output is correct
39 Correct 1626 ms 25448 KB Output is correct
40 Correct 1604 ms 25284 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 8536 KB Output is correct
2 Correct 3 ms 8540 KB Output is correct
3 Correct 3 ms 8540 KB Output is correct
4 Correct 4 ms 8540 KB Output is correct
5 Correct 3 ms 8640 KB Output is correct
6 Correct 4 ms 8536 KB Output is correct
7 Correct 3 ms 8540 KB Output is correct
8 Correct 3 ms 8540 KB Output is correct
9 Correct 3 ms 8540 KB Output is correct
10 Correct 3 ms 8540 KB Output is correct
11 Correct 154 ms 23124 KB Output is correct
12 Correct 152 ms 23212 KB Output is correct
13 Correct 161 ms 23160 KB Output is correct
14 Correct 186 ms 22972 KB Output is correct
15 Correct 153 ms 23052 KB Output is correct
16 Correct 168 ms 23120 KB Output is correct
17 Correct 170 ms 23076 KB Output is correct
18 Correct 146 ms 23256 KB Output is correct
19 Correct 153 ms 22856 KB Output is correct
20 Correct 157 ms 23376 KB Output is correct
21 Correct 160 ms 23000 KB Output is correct
22 Correct 164 ms 23116 KB Output is correct
23 Correct 163 ms 23196 KB Output is correct
24 Correct 168 ms 23124 KB Output is correct
25 Correct 168 ms 23124 KB Output is correct
26 Correct 149 ms 22984 KB Output is correct
27 Correct 173 ms 23184 KB Output is correct
28 Correct 155 ms 22868 KB Output is correct
29 Correct 160 ms 23008 KB Output is correct
30 Correct 158 ms 23120 KB Output is correct
31 Correct 155 ms 23120 KB Output is correct
32 Correct 168 ms 23124 KB Output is correct
33 Correct 178 ms 23240 KB Output is correct
34 Correct 145 ms 22864 KB Output is correct
35 Correct 159 ms 23128 KB Output is correct
36 Correct 168 ms 23120 KB Output is correct
37 Correct 164 ms 23120 KB Output is correct
38 Correct 166 ms 23124 KB Output is correct
39 Correct 167 ms 22960 KB Output is correct
40 Correct 161 ms 23124 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 8536 KB Output is correct
2 Correct 3 ms 8540 KB Output is correct
3 Correct 3 ms 8540 KB Output is correct
4 Correct 4 ms 8540 KB Output is correct
5 Correct 3 ms 8640 KB Output is correct
6 Correct 4 ms 8536 KB Output is correct
7 Correct 3 ms 8540 KB Output is correct
8 Correct 3 ms 8540 KB Output is correct
9 Correct 3 ms 8540 KB Output is correct
10 Correct 3 ms 8540 KB Output is correct
11 Correct 1528 ms 23380 KB Output is correct
12 Correct 1596 ms 23024 KB Output is correct
13 Correct 1603 ms 22072 KB Output is correct
14 Correct 1547 ms 22356 KB Output is correct
15 Correct 1574 ms 23632 KB Output is correct
16 Correct 1542 ms 22524 KB Output is correct
17 Correct 1558 ms 22512 KB Output is correct
18 Correct 1469 ms 24220 KB Output is correct
19 Correct 1582 ms 21188 KB Output is correct
20 Correct 1553 ms 22972 KB Output is correct
21 Correct 1582 ms 26272 KB Output is correct
22 Correct 1635 ms 26440 KB Output is correct
23 Correct 1834 ms 25416 KB Output is correct
24 Correct 1715 ms 25336 KB Output is correct
25 Correct 1570 ms 27500 KB Output is correct
26 Correct 1609 ms 26224 KB Output is correct
27 Correct 1660 ms 25824 KB Output is correct
28 Correct 1479 ms 28148 KB Output is correct
29 Correct 1738 ms 24352 KB Output is correct
30 Correct 1539 ms 26300 KB Output is correct
31 Correct 1604 ms 26260 KB Output is correct
32 Correct 1645 ms 26332 KB Output is correct
33 Correct 1563 ms 25392 KB Output is correct
34 Correct 1642 ms 25388 KB Output is correct
35 Correct 1642 ms 25812 KB Output is correct
36 Correct 1486 ms 24144 KB Output is correct
37 Correct 1522 ms 26336 KB Output is correct
38 Correct 1676 ms 24156 KB Output is correct
39 Correct 1626 ms 25448 KB Output is correct
40 Correct 1604 ms 25284 KB Output is correct
41 Correct 154 ms 23124 KB Output is correct
42 Correct 152 ms 23212 KB Output is correct
43 Correct 161 ms 23160 KB Output is correct
44 Correct 186 ms 22972 KB Output is correct
45 Correct 153 ms 23052 KB Output is correct
46 Correct 168 ms 23120 KB Output is correct
47 Correct 170 ms 23076 KB Output is correct
48 Correct 146 ms 23256 KB Output is correct
49 Correct 153 ms 22856 KB Output is correct
50 Correct 157 ms 23376 KB Output is correct
51 Correct 160 ms 23000 KB Output is correct
52 Correct 164 ms 23116 KB Output is correct
53 Correct 163 ms 23196 KB Output is correct
54 Correct 168 ms 23124 KB Output is correct
55 Correct 168 ms 23124 KB Output is correct
56 Correct 149 ms 22984 KB Output is correct
57 Correct 173 ms 23184 KB Output is correct
58 Correct 155 ms 22868 KB Output is correct
59 Correct 160 ms 23008 KB Output is correct
60 Correct 158 ms 23120 KB Output is correct
61 Correct 155 ms 23120 KB Output is correct
62 Correct 168 ms 23124 KB Output is correct
63 Correct 178 ms 23240 KB Output is correct
64 Correct 145 ms 22864 KB Output is correct
65 Correct 159 ms 23128 KB Output is correct
66 Correct 168 ms 23120 KB Output is correct
67 Correct 164 ms 23120 KB Output is correct
68 Correct 166 ms 23124 KB Output is correct
69 Correct 167 ms 22960 KB Output is correct
70 Correct 161 ms 23124 KB Output is correct
71 Correct 1841 ms 47488 KB Output is correct
72 Correct 1841 ms 47608 KB Output is correct
73 Execution timed out 2001 ms 46280 KB Time limit exceeded
74 Halted 0 ms 0 KB -