Number of good substrings
InterviewTime limit2sMemory limit512 MB
Count how many distinct substrings of s contain at most k bad letters, counting equal substrings once.
- Level
Medium6 of 10
- Topics
- String, Hash map, Sliding window
- Solved
- No attempts yet
Problem
You are given a string made of lowercase English letters. Each of the 26 letters is either good or bad.
For a string of length , the substring () is .
A substring is good if at most of the letters are bad.
Write a program that counts the distinct good substrings of . Two substrings and count as different when . Substrings with the same content at different positions are counted once.
Input
The first line contains a string of lowercase English letters. The length of is at most 1500.
The second line contains a string of length 26 made of 0 and 1. If the -th character is 1, the -th letter is good, and if it is 0, that letter is bad. The first character stands for the letter 'a', and the second one stands for 'b'.
The third line contains ().
Output
Print the number of distinct good substrings of .