#P16231. [蓝桥杯 2026 省 A] 基因研究

    ID: 18265 远端评测题 1000ms 512MiB 尝试: 0 已通过: 0 显示难度提高 上传者: 标签>动态规划 DP概率论KMP 算法有限状态自动机2026蓝桥杯省赛

[蓝桥杯 2026 省 A] 基因研究

Problem Description

The four bases of a DNA molecule are denoted as A, T, G, and C. Each person’s gene sequence can be regarded as a string of length nn consisting of the four characters A, T, G, and C.

Xiaolan is studying a disease. He observes that this disease has a fixed susceptible sequence (which can also be regarded as a string consisting of A, T, G, and C). If a person’s gene sequence contains a substring that is exactly equal to this susceptible sequence, then this person is called “susceptible”. If none of the substrings of the gene sequence is equal to this susceptible sequence, then this person is called “not susceptible”.

Xiaolan hopes to estimate the proportion of “susceptible” people in the city based on the gene sequences of the population.

However, it is very difficult to directly obtain the complete gene sequence of every person in the city. Therefore, Xiaolan uses sampling statistics: through extensive sampling, he estimates, for each position in the city, the proportion of people whose base at that position is A, T, G, or C. We can understand this as: among all people’s gene sequences, what are the proportions of A, T, G, and C at the ii-th position, respectively.

To simplify the model, Xiaolan makes the following assumption: for any person, the base distribution at each position of their gene sequence is exactly the same as the sampling result, and bases at different positions are independent. That is, even if the bases at some positions are already determined, the bases at the remaining positions are still generated independently according to the distributions of the corresponding positions.

Now, Xiaolan decides to compute these probabilities modulo 998244353998244353: if the proportion of “susceptible” people is pq\frac{p}{q}, then Xiaolan wants to obtain an integer xx such that x×qp(mod998244353)x \times q \equiv p \pmod{998244353}. Given the susceptible sequence and the probability distribution of the four bases at each position, please help Xiaolan compute and output this integer xx.

Input Format

The first line contains two positive integers n,mn, m, representing the length of the gene sequence and the length of the susceptible sequence, respectively.

The second line contains a string ss of length mm, consisting only of A, T, G, and C, representing the susceptible sequence corresponding to the disease.

The next nn lines each contain four non-negative integers ai,ti,gi,cia_i, t_i, g_i, c_i. Here:

  • aia_i denotes the probability that the base at position ii is A (modulo 998244353998244353).
  • tit_i denotes the probability that the base at position ii is T (modulo 998244353998244353).
  • gig_i denotes the probability that the base at position ii is G (modulo 998244353998244353).
  • cic_i denotes the probability that the base at position ii is C (modulo 998244353998244353).

It is guaranteed that for any ii, (ai+ti+gi+ci)mod998244353=1(a_i + t_i + g_i + c_i) \bmod 998244353 = 1.

Output Format

Output one line containing a non-negative integer, representing the proportion of people whose gene sequence contains the susceptible sequence as a substring, under modulo 998244353998244353.

3 2
AA
499122177 499122177 0 0
499122177 0 499122177 0
499122177 0 0 499122177
623902721

Hint

Sample Explanation

The gene sequence has 33 positions:

  • At position 11, the probability is 12\frac{1}{2} to be AA, and 12\frac{1}{2} to be TT.
  • At position 22, the probability is 12\frac{1}{2} to be AA, and 12\frac{1}{2} to be GG.
  • At position 33, the probability is 12\frac{1}{2} to be AA, and 12\frac{1}{2} to be CC.

The susceptible sequence is AAAA. Therefore, a person is considered “susceptible” if and only if their gene sequence contains the substring AAAA.

Among all possible generated gene sequences, there are 33 that satisfy the condition: AACAAC, TAATAA, and AAAAAA. Each of these three sequences occurs with probability 18\frac{1}{8}, so the total proportion of “susceptible” people is $\frac{1}{8} + \frac{1}{8} + \frac{1}{8} = \frac{3}{8}$, and its result modulo 998244353998244353 is 623902721623902721.

Constraints

For 30%30\% of the testdata, 1mn51 \le m \le n \le 5.

There is another 20%20\% of the testdata where ai=ti=gi=cia_i = t_i = g_i = c_i.

For 100%100\% of the testdata, 1mn30001 \le m \le n \le 3000, 0ai,ti,gi,ci<9982443530 \le a_i, t_i, g_i, c_i < 998244353.

Translated by ChatGPT 5