#P17125. [ICPC 2025 Shanghai R] Flower' s land 3

[ICPC 2025 Shanghai R] Flower' s land 3

Problem Description

There is a binary string s1s_1 of length mm stored on disk #1\#1.

Then, there are n1n - 1 operations. In the ii-th operation, a disk 1pi+1i1 \le p_{i+1} \le i is chosen, and the string spi+1s_{p_{i+1}} on that disk is copied to disk i+1i + 1, producing si+1s_{i+1}. However, during the copying process, up to kk bits may be flipped (i.e., errors occur in at most kk positions).

You are given all the final nn binary strings s1,s2,,sns_1, s_2, \cdots, s_n, each of length mm. Your task is to determine how many possible sequences p2,p3,,pnp_2, p_3, \cdots, p_n could result in this final configuration.

Since the answer can be large, you only need to find the answer modulo 998244353998244353.

Input Format

The first line of the input contains three integers nn, mm, kk (2n50002 \le n \le 5000, 4m150004 \le m \le 15000, 1k31 \le k \le 3), described in the statement. It is guaranteed that mm is a multiple of 44.

Each of the next nn lines contains a hexadecimal string sis_i' of length m/4m/4. Each character of sis_i' is one of 00-99 or AA-FF, where A=10A = 10, B=11B = 11, \cdots, F=15F = 15.

Each bit in the hexadecimal representation sis_i' corresponds to 44 consecutive bits in the binary string sis_i. Specifically, for each bit si,js'_{i,j}, it can be proved that there exists a unique tuple (a,b,c,d)(a,b,c,d) satisfying si,j=8a+4b+2c+ds'_{i,j} = 8a + 4b + 2c + d and a,b,c,d{0,1}a,b,c,d \in \{0,1\}. Bits in the binary string sis_i satisfy $(s_{i,4j}, s_{i,4j+1}, s_{i,4j+2}, s_{i,4j+3}) = (a,b,c,d)$.

Output Format

Print an integer — the number of valid sequences (p2,p3,,pn)(p_2, p_3, \cdots, p_n) modulo 998244353998244353.

5 8 2
95
05
BD
9C
BD
6