Submission #544291

# Submission time Handle Problem Language Result Execution time Memory
544291 2022-04-01T15:14:51 Z valerikk Snake Escaping (JOI18_snake_escaping) C++17
100 / 100
1022 ms 43184 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int L = 21;
const int M = (1 << L) + 7;
const int K = 6;

int l, q;
int m;
char s[M];
int a[M];
int f[M];
int g[M];

int main() {
	cin >> l >> q >> s;

	m = (1 << l);
	for (int i = 0; i < m; ++i) {
		a[i] = s[i] - '0';
	}

	for (int i = 0; i < m; ++i) {
		f[i] = a[i];
		g[i] = a[i];
	}	
	for (int j = 0; j < l; ++j) {
		for (int i = 0; i < m; ++i) {
			if ((i >> j) & 1) {
				f[i] += f[i ^ (1 << j)];
				g[i ^ (1 << j)] += g[i];
			}
		}
	}

	while (q--) {
		/* int x;
		scanf("%d", &x); */
		static int t[3];
		memset(t, 0, sizeof(t));
		static char tt[L];
		scanf("%s", tt);
		
		for (int i = l - 1; i >= 0; --i) {
			/* t[x % 3] |= (1 << i);
			x /= 3; */
			t[tt[i] == '?' ? 2 : tt[i] - '0'] |= (1 << (l - i - 1)); 
		}

		if (__builtin_popcount(t[1]) <= K) {
			int ans = 0;
			int ppc = __builtin_popcount(t[1]);
			for (int z = t[1]; ; z = (z - 1) & t[1]) {
				ans += (((ppc ^ __builtin_popcount(z)) & 1) ? -1 : 1) * f[t[2] | z];
				if (z == 0) break;
			}
			printf("%d\n", ans);
		} else if (__builtin_popcount(t[0]) <= K) {
			int ans = 0;
			int ppc = __builtin_popcount(t[0]);
			for (int z = t[0]; ; z = (z - 1) & t[0]) {
				ans += (((ppc ^ __builtin_popcount(z)) & 1) ? -1 : 1) * g[t[1] ^ t[0] ^ z];
				if (z == 0) break;
			}
			printf("%d\n", ans);
		} else {
			assert(__builtin_popcount(t[2]) <= K);
			int ans = 0;
			for (int z = t[2]; ; z = (z - 1) & t[2]) {
				ans += a[t[1] | z];
				if (z == 0) break;
			}
			printf("%d\n", ans);
		}
	}
	return 0;
}

Compilation message

snake_escaping.cpp: In function 'int main()':
snake_escaping.cpp:45:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   45 |   scanf("%s", tt);
      |   ~~~~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 312 KB Output is correct
5 Correct 1 ms 316 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 312 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 320 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 312 KB Output is correct
5 Correct 1 ms 316 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 312 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 320 KB Output is correct
11 Correct 336 ms 6000 KB Output is correct
12 Correct 200 ms 5688 KB Output is correct
13 Correct 235 ms 4952 KB Output is correct
14 Correct 235 ms 5068 KB Output is correct
15 Correct 228 ms 6092 KB Output is correct
16 Correct 273 ms 5196 KB Output is correct
17 Correct 267 ms 5312 KB Output is correct
18 Correct 199 ms 7108 KB Output is correct
19 Correct 327 ms 4096 KB Output is correct
20 Correct 308 ms 5672 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 312 KB Output is correct
5 Correct 1 ms 316 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 312 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 320 KB Output is correct
11 Correct 336 ms 6000 KB Output is correct
12 Correct 200 ms 5688 KB Output is correct
13 Correct 235 ms 4952 KB Output is correct
14 Correct 235 ms 5068 KB Output is correct
15 Correct 228 ms 6092 KB Output is correct
16 Correct 273 ms 5196 KB Output is correct
17 Correct 267 ms 5312 KB Output is correct
18 Correct 199 ms 7108 KB Output is correct
19 Correct 327 ms 4096 KB Output is correct
20 Correct 308 ms 5672 KB Output is correct
21 Correct 488 ms 6184 KB Output is correct
22 Correct 220 ms 6288 KB Output is correct
23 Correct 288 ms 5316 KB Output is correct
24 Correct 295 ms 5196 KB Output is correct
25 Correct 253 ms 7140 KB Output is correct
26 Correct 329 ms 5652 KB Output is correct
27 Correct 321 ms 5776 KB Output is correct
28 Correct 224 ms 8192 KB Output is correct
29 Correct 456 ms 4124 KB Output is correct
30 Correct 309 ms 6344 KB Output is correct
31 Correct 317 ms 6216 KB Output is correct
32 Correct 296 ms 6096 KB Output is correct
33 Correct 270 ms 4984 KB Output is correct
34 Correct 320 ms 5108 KB Output is correct
35 Correct 319 ms 5640 KB Output is correct
36 Correct 232 ms 4128 KB Output is correct
37 Correct 215 ms 6044 KB Output is correct
38 Correct 379 ms 3916 KB Output is correct
39 Correct 460 ms 5216 KB Output is correct
40 Correct 353 ms 4812 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 312 KB Output is correct
5 Correct 1 ms 316 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 312 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 320 KB Output is correct
11 Correct 62 ms 15396 KB Output is correct
12 Correct 64 ms 15228 KB Output is correct
13 Correct 69 ms 15108 KB Output is correct
14 Correct 75 ms 15180 KB Output is correct
15 Correct 65 ms 15224 KB Output is correct
16 Correct 85 ms 15240 KB Output is correct
17 Correct 86 ms 15204 KB Output is correct
18 Correct 64 ms 15352 KB Output is correct
19 Correct 62 ms 15012 KB Output is correct
20 Correct 63 ms 15220 KB Output is correct
21 Correct 70 ms 15244 KB Output is correct
22 Correct 79 ms 15160 KB Output is correct
23 Correct 79 ms 15228 KB Output is correct
24 Correct 99 ms 15188 KB Output is correct
25 Correct 100 ms 15212 KB Output is correct
26 Correct 69 ms 15228 KB Output is correct
27 Correct 75 ms 15360 KB Output is correct
28 Correct 75 ms 15068 KB Output is correct
29 Correct 104 ms 15516 KB Output is correct
30 Correct 77 ms 15860 KB Output is correct
31 Correct 85 ms 15772 KB Output is correct
32 Correct 95 ms 15900 KB Output is correct
33 Correct 91 ms 15808 KB Output is correct
34 Correct 78 ms 15764 KB Output is correct
35 Correct 84 ms 15820 KB Output is correct
36 Correct 98 ms 15948 KB Output is correct
37 Correct 89 ms 15872 KB Output is correct
38 Correct 84 ms 15796 KB Output is correct
39 Correct 86 ms 15880 KB Output is correct
40 Correct 81 ms 15780 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 312 KB Output is correct
5 Correct 1 ms 316 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 312 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 320 KB Output is correct
11 Correct 336 ms 6000 KB Output is correct
12 Correct 200 ms 5688 KB Output is correct
13 Correct 235 ms 4952 KB Output is correct
14 Correct 235 ms 5068 KB Output is correct
15 Correct 228 ms 6092 KB Output is correct
16 Correct 273 ms 5196 KB Output is correct
17 Correct 267 ms 5312 KB Output is correct
18 Correct 199 ms 7108 KB Output is correct
19 Correct 327 ms 4096 KB Output is correct
20 Correct 308 ms 5672 KB Output is correct
21 Correct 488 ms 6184 KB Output is correct
22 Correct 220 ms 6288 KB Output is correct
23 Correct 288 ms 5316 KB Output is correct
24 Correct 295 ms 5196 KB Output is correct
25 Correct 253 ms 7140 KB Output is correct
26 Correct 329 ms 5652 KB Output is correct
27 Correct 321 ms 5776 KB Output is correct
28 Correct 224 ms 8192 KB Output is correct
29 Correct 456 ms 4124 KB Output is correct
30 Correct 309 ms 6344 KB Output is correct
31 Correct 317 ms 6216 KB Output is correct
32 Correct 296 ms 6096 KB Output is correct
33 Correct 270 ms 4984 KB Output is correct
34 Correct 320 ms 5108 KB Output is correct
35 Correct 319 ms 5640 KB Output is correct
36 Correct 232 ms 4128 KB Output is correct
37 Correct 215 ms 6044 KB Output is correct
38 Correct 379 ms 3916 KB Output is correct
39 Correct 460 ms 5216 KB Output is correct
40 Correct 353 ms 4812 KB Output is correct
41 Correct 62 ms 15396 KB Output is correct
42 Correct 64 ms 15228 KB Output is correct
43 Correct 69 ms 15108 KB Output is correct
44 Correct 75 ms 15180 KB Output is correct
45 Correct 65 ms 15224 KB Output is correct
46 Correct 85 ms 15240 KB Output is correct
47 Correct 86 ms 15204 KB Output is correct
48 Correct 64 ms 15352 KB Output is correct
49 Correct 62 ms 15012 KB Output is correct
50 Correct 63 ms 15220 KB Output is correct
51 Correct 70 ms 15244 KB Output is correct
52 Correct 79 ms 15160 KB Output is correct
53 Correct 79 ms 15228 KB Output is correct
54 Correct 99 ms 15188 KB Output is correct
55 Correct 100 ms 15212 KB Output is correct
56 Correct 69 ms 15228 KB Output is correct
57 Correct 75 ms 15360 KB Output is correct
58 Correct 75 ms 15068 KB Output is correct
59 Correct 104 ms 15516 KB Output is correct
60 Correct 77 ms 15860 KB Output is correct
61 Correct 85 ms 15772 KB Output is correct
62 Correct 95 ms 15900 KB Output is correct
63 Correct 91 ms 15808 KB Output is correct
64 Correct 78 ms 15764 KB Output is correct
65 Correct 84 ms 15820 KB Output is correct
66 Correct 98 ms 15948 KB Output is correct
67 Correct 89 ms 15872 KB Output is correct
68 Correct 84 ms 15796 KB Output is correct
69 Correct 86 ms 15880 KB Output is correct
70 Correct 81 ms 15780 KB Output is correct
71 Correct 432 ms 18696 KB Output is correct
72 Correct 458 ms 40356 KB Output is correct
73 Correct 597 ms 38828 KB Output is correct
74 Correct 790 ms 39212 KB Output is correct
75 Correct 505 ms 41136 KB Output is correct
76 Correct 957 ms 39544 KB Output is correct
77 Correct 861 ms 39512 KB Output is correct
78 Correct 391 ms 43184 KB Output is correct
79 Correct 434 ms 37200 KB Output is correct
80 Correct 452 ms 40548 KB Output is correct
81 Correct 638 ms 40148 KB Output is correct
82 Correct 753 ms 39244 KB Output is correct
83 Correct 506 ms 38496 KB Output is correct
84 Correct 996 ms 39172 KB Output is correct
85 Correct 868 ms 39444 KB Output is correct
86 Correct 380 ms 37232 KB Output is correct
87 Correct 435 ms 40340 KB Output is correct
88 Correct 491 ms 37220 KB Output is correct
89 Correct 594 ms 38864 KB Output is correct
90 Correct 517 ms 39264 KB Output is correct
91 Correct 475 ms 38360 KB Output is correct
92 Correct 941 ms 39544 KB Output is correct
93 Correct 1022 ms 39340 KB Output is correct
94 Correct 382 ms 37172 KB Output is correct
95 Correct 769 ms 39244 KB Output is correct
96 Correct 863 ms 39260 KB Output is correct
97 Correct 812 ms 39324 KB Output is correct
98 Correct 777 ms 39328 KB Output is correct
99 Correct 783 ms 39280 KB Output is correct
100 Correct 775 ms 39284 KB Output is correct