F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

Nested String

Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 524288/524288 K (Java/Others)
Total Submission(s): 832    Accepted Submission(s): 198


Problem Description
Given two strings $T_1$ and $T_2$, a string $X$ is $T$-nested if and only if $X$ can be represented as the string obtained by inserting $T_2$ at a position in $T_1$. For example, if $T_1=\texttt{abcd}$ and $T_2=\texttt{ef}$, then $\texttt{efabcd}$, $\texttt{aefbcd}$ and $\texttt{abcdef}$ are all $T$-nested strings.

Given strings $S$, $T_1$, and $T_2$, 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 $T_2$ in $T_1$ are different. A substring of $S$ means a continuous sequence of characters from string $S$.
 

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

The first line contains a single integer $T$ ($1\le T\le 20$), denoting the number of test cases.

The first line of each test case contains two strings $T_1$ and $T_2$ ($|T_1|+|T_2|\le |S|$) separated by a single space.

The second line of each test case contains a single string $S$ ($|S|\le 10^7$).

It is guaranteed that $S$, $T_1$, and $T_2$ all consist only of lowercase letters and $\sum |S|\le 2\times 10^7$. Here, $|S|$ means the length of string $S$.
 

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

Sample Input
3 abab ab abababab ab a aaabbaabaa aba ab ababaabbabaab
 

Sample Output
6 5 5
 

Hint
In the first test case, the $6$ $T$-nested substrings are (the substring is underlined and the part from $T_2$ is highlighted in bold):

  • $\underline{\textbf{ab}\text{abab}}\text{ab}$

  • $\underline{\text{ab}\textbf{ab}\text{ab}}\text{ab}$

  • $\underline{\text{abab}\textbf{ab}}\text{ab}$

  • $\text{ab}\underline{\textbf{ab}\text{abab}}$

  • $\text{ab}\underline{\text{ab}\textbf{ab}\text{ab}}$

  • $\text{ab}\underline{\text{abab}\textbf{ab}}$

 

Source
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2024 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.000000(s) query 1, Server time : 2024-11-22 09:03:31, Gzip enabled