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 a "-CON string". For example, qqqq
is a "-CON string", while aaab
is not any type of "CON string".
Lily White composed an array . It contains strings of length that she will use to herald spring. For each permutation of , let us denote current permutation as . Lily White concatenates all the string in array in the order of into a string of length .
As she likes -CON strings, she wants to know the sum of the number of "-CON string" in all non-empty substrings of composed by all permutations. Since the answer may be enormous, just print the answer taken modulo (a large prime).
输入格式
The first line contains three integers .
Then lines follow, each line contains a string of length . The string in the-th line represents .
输出格式
Print a single integer - the answer taken modulo .
题目大意
给定若干长度为 的字符串 ,给定常数 ,试求出对于所有的长度为 的排列 ,将 依次拼接形成的长字符串 中,有多少个位置 满足 为同一种字符。请输出位置数的和 的值。
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 , the formed is
aaabaabaa
, none on the non-empty substring in this string are "-CON string". - For permutation , the formed is
aaabaabaa
, none on the non-empty substring in this string are "-CON string". - For permutation , the formed is
baaaaabaa
, this string has one substringaaaaa
which is a "-CON string". - For permutation , the formed is
baabaaaaa
, this string has one substringaaaaa
which is a "-CON string". - For permutation , the formed is
baaaaabaa
, this string has one substringaaaaa
which is a "-CON string". - For permutation , the formed is
baabaaaaa
, this string has one substringaaaaa
which is a "-CON string".
In summary, the answer is .
Sample #2
In all of the full permutation of length , there will be six different : xyzqaqaba
, xyzabaqaq
, qaqxyzaba
, qaqabaxyz
, abaqaqxyz
, and abaxyzqaq
. None of these has a non-empty substrings which is a "-CON string". So the answer is .
Constraints
. contains only lowercase English letters.