luogu#P7943. 「Wdcfr-1」CONsecutive and CONcat (hard version)

「Wdcfr-1」CONsecutive and CONcat (hard version)

题目描述

Lily White is playing with strings. Being a yousei, she is not capable of complex speech. Thus, she likes strings that only contain one kind of letter, she calls such strings of length xx a "xx-CON string". For example, qqqq is a "44-CON string", while aaab is not any type of "CON string".

Lily White composed an array aa. It contains nn strings of length mm that she will use to herald spring. For each permutation of 1,2,,n1,2,\ldots, n, let us denote current permutation as p={p1,p2,,pn}p=\{p_1,p_2,\cdots,p_n\}. Lily White concatenates all the string in array aa in the order of ap1,ap2,,apna_{p_1},a_{p_2},\cdots,a_{p_n} into a string ss of length nmnm .

As she likes kk-CON strings, she wants to know the sum of the number of "kk-CON string" in all non-empty substrings of ss composed by all n!n! permutations. Since the answer may be enormous, just print the answer taken modulo 998,244,353998,244,353 (a large prime).

输入格式

The first line contains three integers n,m,kn,m,k.

Then nn lines follow, each line contains a string of length mm. The string in the(i+1)(i+1)-th line represents aia_i.

输出格式

Print a single integer - the answer taken modulo 998,244,353998,244,353.

题目大意

给定若干长度为 mm 的字符串 a1,a2,...,ana_1,a_2,...,a_n,给定常数 kk,试求出对于所有的长度为 nn 的排列 pp,将 ap1,ap2,...,apna_{p_1},a_{p_2},...,a_{p_n} 依次拼接形成的长字符串 ss 中,有多少个位置 xx 满足 sx,sx+1,...,sx+k1s_x,s_{x+1},...,s_{x+k-1} 为同一种字符。请输出位置数的和 mod 998244353\bmod \space998244353 的值。

3 3 5
aaa
baa
baa

4
3 3 2
xyz
qaq
aba

0
5 3 2
cca
cbb
acb
bbb
acb

600
5 3 5
aba
bbb
bbb
aba
bcb

120

提示

Explanation

Sample #1

  • For permutation 1,2,31,2,3, the formed ss is aaabaabaa, none on the non-empty substring in this string are "55-CON string".
  • For permutation 1,3,21,3,2, the formed ss is aaabaabaa, none on the non-empty substring in this string are "55-CON string".
  • For permutation 2,1,32,1,3, the formed ss is baaaaabaa, this string has one substring aaaaa which is a "55-CON string".
  • For permutation 2,3,12,3,1, the formed ss is baabaaaaa, this string has one substring aaaaa which is a "55-CON string".
  • For permutation 3,1,23,1,2, the formed ss is baaaaabaa, this string has one substring aaaaa which is a "55-CON string".
  • For permutation 3,2,13,2,1, the formed ss is baabaaaaa, this string has one substring aaaaa which is a "55-CON string".

In summary, the answer is 0+0+1+1+1+1=40+0+1+1+1+1=4.

Sample #2

In all of the full permutation of length 33, there will be six different ss: xyzqaqaba, xyzabaqaq, qaqxyzaba, qaqabaxyz, abaqaqxyz, and abaxyzqaq. None of these has a non-empty substrings which is a "22-CON string". So the answer is 00.

Constraints

2knm106; 1m1002\le k \le n\cdot m\le 10^6;\ 1\le m \le 100. aia_i contains only lowercase English letters.