问题 F: Nested String

内存限制:256 MB 时间限制:2 S
题面:传统 评测方式:文本比较 上传者:
提交:1 通过:1

题目描述

Given two strings �1T1 and �2T2, a string X is T-nested if and only if X can be represented as the string obtained by inserting �2T2 at a position in �1T1. For example, if �1=abcdT1=abcd and �2=efT2=ef, then efabcdefabcdaefbcdaefbcd and abcdefabcdef are all T-nested strings.

Given strings S�1T1, and �2T2, your task is to compute the count of distinct T-nested substrings in S. Two nested substrings are considered distinct if they either occur at different positions in S, or the insert positions of �2T2 in �1T1 are different. A substring of S means a continuous sequence of characters from string S.

输入格式

Ensure to use cin/cout and disable synchronization with stdio to avoid unexpected TLE verdict.

The first line contains a single integer T (1≤�≤201T20), denoting the number of test cases.

The first line of each test case contains two strings �1T1 and �2T2 (∣�1∣+∣�2∣≤∣�∣T1+T2S) separated by a single space.

The second line of each test case contains a single string S (∣�∣≤107S107).

It is guaranteed that S�1T1, and �2T2 all consist only of lowercase letters and ∑∣�∣≤2×107S2×107. Here, ∣�∣S means the length of string S.

输出格式

For each test case, output an integer in a single line representing the number of distinct T-nested substrings in S.

输入样例 复制

3
abab ab
abababab
ab a
aaabbaabaa
aba ab
ababaabbabaab

输出样例 复制

6
5
5

数据范围与提示

In the first test case, the 6 T-nested substrings are (the substring is underlined and the part from T2 is highlighted in bold):
  • ababab‾ababababab
  • ababab‾ababababab
  • ababab‾ababababab
  • abababab‾abababab
  • abababab‾abababab
  • abababab‾abababab

分类标签