Subsequences in Substrings
Time limit2sMemory limit512 MB
Count how many substrings of s contain t as a subsequence at least once.
- Level
Medium7 of 10
- Topics
- Two pointers, Dynamic programming, String, Greedy
- Solved
- No attempts yet
Problem
You are given two strings and . Count the number of substrings of that contain as a subsequence at least once.
A substring and a subsequence both consist of characters from the original string, in order. In a substring, the characters must be contiguous in the original string. In a subsequence, they do not have to be contiguous. In the string abcde, ace is a subsequence but not a substring.
If is aa and is a, the answer is 3: [a]a, [aa], and a[a].
Input
Each test case consists of exactly two lines.
The first line contains string (, ), with no other characters. The second line contains string (, , ), with no other characters.
Output
Output a single integer: the number of substrings of that contain as a subsequence at least once.