답안 #523316

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
523316 2022-02-07T12:34:20 Z sidon Snake Escaping (JOI18_snake_escaping) C++17
58 / 100
2000 ms 36932 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, inp;
char t[N][20-B];

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 >> inp;
		reverse(begin(inp), end(inp));
		inp.resize(20, '0');

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

		for(int k = 0; k < 20-B; ++k)
			t[i][k] = inp[k+B];
	}

	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][k] != '?' && bool(s & (1<<k)) != (t[i][k] - '0'))
					OK = 0;
			if(OK)
				ans[i] += dp[id[i]];
		}
	}

	for(int i = 0; i < Q; ++i)
		cout << ans[i] << '\n';
}
# 결과 실행 시간 메모리 Grader output
1 Correct 921 ms 7628 KB Output is correct
2 Correct 943 ms 7628 KB Output is correct
3 Correct 954 ms 7628 KB Output is correct
4 Correct 946 ms 7628 KB Output is correct
5 Correct 939 ms 7628 KB Output is correct
6 Correct 935 ms 7628 KB Output is correct
7 Correct 988 ms 7628 KB Output is correct
8 Correct 936 ms 7608 KB Output is correct
9 Correct 946 ms 7628 KB Output is correct
10 Correct 950 ms 7628 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 921 ms 7628 KB Output is correct
2 Correct 943 ms 7628 KB Output is correct
3 Correct 954 ms 7628 KB Output is correct
4 Correct 946 ms 7628 KB Output is correct
5 Correct 939 ms 7628 KB Output is correct
6 Correct 935 ms 7628 KB Output is correct
7 Correct 988 ms 7628 KB Output is correct
8 Correct 936 ms 7608 KB Output is correct
9 Correct 946 ms 7628 KB Output is correct
10 Correct 950 ms 7628 KB Output is correct
11 Execution timed out 2028 ms 36932 KB Time limit exceeded
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 921 ms 7628 KB Output is correct
2 Correct 943 ms 7628 KB Output is correct
3 Correct 954 ms 7628 KB Output is correct
4 Correct 946 ms 7628 KB Output is correct
5 Correct 939 ms 7628 KB Output is correct
6 Correct 935 ms 7628 KB Output is correct
7 Correct 988 ms 7628 KB Output is correct
8 Correct 936 ms 7608 KB Output is correct
9 Correct 946 ms 7628 KB Output is correct
10 Correct 950 ms 7628 KB Output is correct
11 Execution timed out 2028 ms 36932 KB Time limit exceeded
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 921 ms 7628 KB Output is correct
2 Correct 943 ms 7628 KB Output is correct
3 Correct 954 ms 7628 KB Output is correct
4 Correct 946 ms 7628 KB Output is correct
5 Correct 939 ms 7628 KB Output is correct
6 Correct 935 ms 7628 KB Output is correct
7 Correct 988 ms 7628 KB Output is correct
8 Correct 936 ms 7608 KB Output is correct
9 Correct 946 ms 7628 KB Output is correct
10 Correct 950 ms 7628 KB Output is correct
11 Correct 1239 ms 8588 KB Output is correct
12 Correct 1232 ms 8712 KB Output is correct
13 Correct 1149 ms 8588 KB Output is correct
14 Correct 1219 ms 8584 KB Output is correct
15 Correct 1171 ms 8708 KB Output is correct
16 Correct 1194 ms 8588 KB Output is correct
17 Correct 1179 ms 8584 KB Output is correct
18 Correct 986 ms 8852 KB Output is correct
19 Correct 1000 ms 8552 KB Output is correct
20 Correct 1198 ms 8780 KB Output is correct
21 Correct 1195 ms 8676 KB Output is correct
22 Correct 1186 ms 8588 KB Output is correct
23 Correct 1109 ms 8588 KB Output is correct
24 Correct 1235 ms 8584 KB Output is correct
25 Correct 1192 ms 8584 KB Output is correct
26 Correct 1026 ms 8508 KB Output is correct
27 Correct 1238 ms 8648 KB Output is correct
28 Correct 1016 ms 8464 KB Output is correct
29 Correct 1144 ms 8584 KB Output is correct
30 Correct 1208 ms 8580 KB Output is correct
31 Correct 1106 ms 8588 KB Output is correct
32 Correct 1189 ms 8584 KB Output is correct
33 Correct 1173 ms 8584 KB Output is correct
34 Correct 984 ms 8456 KB Output is correct
35 Correct 1181 ms 8580 KB Output is correct
36 Correct 1160 ms 8596 KB Output is correct
37 Correct 1160 ms 8588 KB Output is correct
38 Correct 1145 ms 8676 KB Output is correct
39 Correct 1164 ms 8676 KB Output is correct
40 Correct 1156 ms 8580 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 921 ms 7628 KB Output is correct
2 Correct 943 ms 7628 KB Output is correct
3 Correct 954 ms 7628 KB Output is correct
4 Correct 946 ms 7628 KB Output is correct
5 Correct 939 ms 7628 KB Output is correct
6 Correct 935 ms 7628 KB Output is correct
7 Correct 988 ms 7628 KB Output is correct
8 Correct 936 ms 7608 KB Output is correct
9 Correct 946 ms 7628 KB Output is correct
10 Correct 950 ms 7628 KB Output is correct
11 Execution timed out 2028 ms 36932 KB Time limit exceeded
12 Halted 0 ms 0 KB -