S3. Searching for Strings
의견: 0
You’re given a string \(N\), called the
needle, and a string \(H\), called the
haystack, both of which contain only lowercase
letters “a"..“z".
Write a program to count the number of distinct permutations of \(N\) which appear as a substring of \(H\) at least once. Note that \(N\) can have anywhere between 1 and \(|N|!\) distinct permutations in total – for
example, the string “aab" has 3 distinct permutations (“aab", “aba", and
“baa").
\((1 \le |N| \le 200\ 000)\)
\((1 \le |H| \le 200\ 000)\)
\(|N| \le 8\)
\(|H| \le 200\)
\(|N| \le 200\)
\(|N| \le 2000\)
\(|H| \le 2000\)
The first line contains \(N\) \((1 \le |N| \le 200\ 000)\), the needle
string.
The second line contains \(H\)
\((1 \le |H| \le 200\ 000)\), the
haystack string.
For 3 of the 15 available marks, \(|N| \le 8\) and \(|H| \le 200\).
For an additional 2 of the 15 available marks, \(|N| \le 200\) and \(|H| \le 200\).
For an additional 2 of the 15 available marks, \(|N| \le 2000\) and \(|H| \le 2000\).
Output consists of one integer, the number of distinct permutations of
\(N\) which appear as a substring of
\(H\).
aab
abacabaa2The permutations “aba" and “baa" each appear as substrings of \(H\) (the former appears twice), while the
permutation “aab" does not appear.
평가 및 의견
S3. Searching for Strings
Log in to rate problems.
아직 의견이 없습니다. 자격이 된다면 위 양식에서 가장 먼저 평가해 보세요.
풀이 제출
S3. Searching for Strings