#P9882. Nested String
Nested String
Nested String
Problem Description
Given two strings and , a string is -nested if and only if can be represented as the string obtained by inserting at a position in . For example, if and , then , and are all -nested strings. Given strings , , and , your task is to compute the count of distinct -nested substrings in . Two nested substrings are considered distinct if they either occur at different positions in , or the insert positions of in are different . A substring of means a continuous sequence of characters from string .
Input
Ensure to use cin/cout and disable synchronization with stdio to avoid unexpected TLE verdict. The first line contains a single integer (), denoting the number of test cases. The first line of each test case contains two strings and () separated by a single space. The second line of each test case contains a single string (). It is guaranteed that , , and all consist only of lowercase letters and . Here, means the length of string .
Output
For each test case, output an integer in a single line representing the number of distinct -nested substrings in .
Sample Input
3
abab ab
abababab
ab a
aaabbaabaa
aba ab
ababaabbabaab
Sample Output
6
5
5
Hint
In the first test case, the -nested substrings are (the substring is underlined and the part from is highlighted in bold):
Source
2023“钉耙编程”中国大学生算法设计超级联赛(8)