#P10694. [SNCPC2024] 双子序列
[SNCPC2024] 双子序列
Problem Description
Little L feels very uncomfortable when he sees strings he dislikes. He also feels uncomfortable when he sees them appear as subsequences.
Given a long string representing the text that Little L needs to read, and exactly two short strings , representing the strings that Little L does not want to see. All three strings consist of lowercase letters.
Little L strongly dislikes having both of these strings appear in the text as subsequences at the same time. He defines the discomfort value of a string as: the product of the number of occurrences of as a subsequence of and the number of occurrences of as a subsequence of .
Since he will read every substring of , you now need to compute the sum of the discomfort values of all substrings of . Since the answer may be too large, you only need to output the result modulo .
A string is a substring of if and only if can be obtained by deleting some characters from the beginning of and some characters from the end of (you may delete zero characters from the prefix/suffix, or delete the entire string to obtain the empty string).
A string is a subsequence of if and only if can be obtained by deleting some characters from (you may delete zero characters, or delete all characters to obtain the empty subsequence).
Input Format
The input consists of three lines, each containing a string of lowercase letters.
The first line is , the second line is , and the third line is . Here, , .
Output Format
Output a single integer representing the computed answer.
iccpcicpc
icpc
ccpc
133
Hint
| Substring start position | Substring end position | icpc count | ccpc count |
|---|---|---|---|
| 1 | 5 | 2 | 1 |
| 6 | |||
| 7 | 4 | 2 | |
| 8 | |||
| 9 | 11 | 9 | |
| 2 | 5 | 0 | 1 |
| 6 | |||
| 7 | 2 | ||
| 8 | |||
| 9 | 1 | 9 | |
| 3 | 3 | ||
| 4 | 1 | ||
| 5 | |||
| 6 | 0 |
In all other substrings, the numbers of occurrences of the two strings as subsequences are both .
The answer is $(2\times 1) \times 2 + (4\times 2) \times 2 + 11\times 9 + (0\times 1)\times 2 + (0\times 2)\times 2 + 1\times 9 + 1\times 3 + (1\times 1)\times 2 + 1\times 0=133$.
Translated by ChatGPT 5