Submission #523313

# Submission time Handle Problem Language Result Execution time Memory
523313 2022-02-07T12:23:17 Z sidon Snake Escaping (JOI18_snake_escaping) C++17
58 / 100
1407 ms 65540 KB
#include <bits/stdc++.h>
using namespace std;

const int B = 13, N = 1<<20, SZ = pow(3, B);

int Q, dp[SZ], ans[N], id[N];
string A, t[N];

int main() {
	ios::sync_with_stdio(0), cin.tie(0);
	cin >> Q >> Q >> A;
	A.resize(N, '0');

	for(int i = 0; i < Q; ++i) {
		cin >> t[i];
		reverse(begin(t[i]), end(t[i]));
		t[i].resize(20, '0');

		for(int k = 0, p = 1; k < B; ++k, p *= 3)
			id[i] += p * ((48 < t[i][k]) + (62 < t[i][k]));
	}

	for(int s = 0; s < (1<<(20-B)); ++s) {
		memset(dp, 0, sizeof dp);

		for(int i = 0; i < (1<<B); ++i) {
			int j = 0;
			for(int k = 0, p = 1; k < B; ++k, p *= 3)
				if(i & (1<<k)) j += p;

			dp[j] += A[i | (s << B)] - '0';
		}

		for(int i = 1; i < SZ; ++i) {
			int j = -1, pw = 1;

			for(int k = 0, p = i; k < B; ++k, p /= 3, pw *= 3)
				if((p % 3) > 1) j = k, k = B;
			
			if(j >= 0)
				pw /= 3, dp[i] = dp[i - pw] + dp[i - 2 * pw];
		}


		for(int i = 0; i < Q; ++i) {
			bool OK = 1;
			for(int k = 0; k < (20-B); ++k)
				if(t[i][B+k] != '?' && bool(s & (1<<k)) != (t[i][B+k] - '0'))
					OK = 0;
			if(OK) ans[i] += dp[id[i]];
		}
	}

	for(int i = 0; i < Q; ++i)
		cout << ans[i] << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 1070 ms 40480 KB Output is correct
2 Correct 1082 ms 40476 KB Output is correct
3 Correct 1064 ms 40476 KB Output is correct
4 Correct 1076 ms 40480 KB Output is correct
5 Correct 1066 ms 40480 KB Output is correct
6 Correct 1082 ms 40476 KB Output is correct
7 Correct 1072 ms 40480 KB Output is correct
8 Correct 1085 ms 40480 KB Output is correct
9 Correct 1097 ms 40396 KB Output is correct
10 Correct 1078 ms 40480 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1070 ms 40480 KB Output is correct
2 Correct 1082 ms 40476 KB Output is correct
3 Correct 1064 ms 40476 KB Output is correct
4 Correct 1076 ms 40480 KB Output is correct
5 Correct 1066 ms 40480 KB Output is correct
6 Correct 1082 ms 40476 KB Output is correct
7 Correct 1072 ms 40480 KB Output is correct
8 Correct 1085 ms 40480 KB Output is correct
9 Correct 1097 ms 40396 KB Output is correct
10 Correct 1078 ms 40480 KB Output is correct
11 Runtime error 116 ms 65540 KB Execution killed with signal 9
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1070 ms 40480 KB Output is correct
2 Correct 1082 ms 40476 KB Output is correct
3 Correct 1064 ms 40476 KB Output is correct
4 Correct 1076 ms 40480 KB Output is correct
5 Correct 1066 ms 40480 KB Output is correct
6 Correct 1082 ms 40476 KB Output is correct
7 Correct 1072 ms 40480 KB Output is correct
8 Correct 1085 ms 40480 KB Output is correct
9 Correct 1097 ms 40396 KB Output is correct
10 Correct 1078 ms 40480 KB Output is correct
11 Runtime error 116 ms 65540 KB Execution killed with signal 9
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1070 ms 40480 KB Output is correct
2 Correct 1082 ms 40476 KB Output is correct
3 Correct 1064 ms 40476 KB Output is correct
4 Correct 1076 ms 40480 KB Output is correct
5 Correct 1066 ms 40480 KB Output is correct
6 Correct 1082 ms 40476 KB Output is correct
7 Correct 1072 ms 40480 KB Output is correct
8 Correct 1085 ms 40480 KB Output is correct
9 Correct 1097 ms 40396 KB Output is correct
10 Correct 1078 ms 40480 KB Output is correct
11 Correct 1398 ms 45416 KB Output is correct
12 Correct 1382 ms 45484 KB Output is correct
13 Correct 1344 ms 45356 KB Output is correct
14 Correct 1383 ms 45408 KB Output is correct
15 Correct 1365 ms 45604 KB Output is correct
16 Correct 1369 ms 45348 KB Output is correct
17 Correct 1396 ms 45352 KB Output is correct
18 Correct 1161 ms 45692 KB Output is correct
19 Correct 1216 ms 45224 KB Output is correct
20 Correct 1404 ms 45484 KB Output is correct
21 Correct 1396 ms 45396 KB Output is correct
22 Correct 1407 ms 45356 KB Output is correct
23 Correct 1305 ms 45284 KB Output is correct
24 Correct 1362 ms 45520 KB Output is correct
25 Correct 1380 ms 45396 KB Output is correct
26 Correct 1197 ms 45268 KB Output is correct
27 Correct 1396 ms 45420 KB Output is correct
28 Correct 1217 ms 45232 KB Output is correct
29 Correct 1360 ms 45352 KB Output is correct
30 Correct 1370 ms 45352 KB Output is correct
31 Correct 1305 ms 45416 KB Output is correct
32 Correct 1379 ms 45348 KB Output is correct
33 Correct 1381 ms 45356 KB Output is correct
34 Correct 1190 ms 45284 KB Output is correct
35 Correct 1383 ms 45476 KB Output is correct
36 Correct 1367 ms 45360 KB Output is correct
37 Correct 1359 ms 45384 KB Output is correct
38 Correct 1364 ms 45352 KB Output is correct
39 Correct 1362 ms 45396 KB Output is correct
40 Correct 1360 ms 45412 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1070 ms 40480 KB Output is correct
2 Correct 1082 ms 40476 KB Output is correct
3 Correct 1064 ms 40476 KB Output is correct
4 Correct 1076 ms 40480 KB Output is correct
5 Correct 1066 ms 40480 KB Output is correct
6 Correct 1082 ms 40476 KB Output is correct
7 Correct 1072 ms 40480 KB Output is correct
8 Correct 1085 ms 40480 KB Output is correct
9 Correct 1097 ms 40396 KB Output is correct
10 Correct 1078 ms 40480 KB Output is correct
11 Runtime error 116 ms 65540 KB Execution killed with signal 9
12 Halted 0 ms 0 KB -