#P12197. Distinct Substrings of Fixed Length
Distinct Substrings of Fixed Length
Distinct Substrings of Fixed Length
Given a string \(s\) of length \(n\) (consisting of lowercase English letters) and an integer \(l\) (with \(1 \le l \le n\)), count the number of different contiguous substrings of \(s\) of length \(l\).
Two substrings are considered different if there exists at least one position where their characters differ.
This problem can be solved by using various techniques including hashing, suffix arrays, suffix automaton, or suffix trees. A straightforward approach is to slide a window of length \(l\) over the string and use a set to collect the distinct substrings.
inputFormat
The input consists of two lines:
- The first line contains a single integer \(l\), the length of the substrings to consider.
- The second line contains the string \(s\), which is guaranteed to have at least \(l\) characters and consists only of lowercase letters.
outputFormat
Output a single integer representing the number of distinct contiguous substrings of \(s\) of length \(l\).
sample
2
abab
2