#P12199. Counting Distinct Substrings
Counting Distinct Substrings
Counting Distinct Substrings
Given a string \(s\) of length \(n\) and an integer \(l\), you are required to determine the number of distinct contiguous substrings of \(s\) with length \(l\). Two substrings are considered different if there exists at least one position where their characters differ.
Although the original problem description mentioned a sophisticated approach using double modulo hashing to avoid collisions (using mod values in the range \( [0,2^{31}) \) and natural overflow on unsigned 64-bit integers), you can solve this problem using any correct method as long as the solution works for all cases.
Formally, you need to count the number of distinct substrings \(s[i...i+l-1]\) for \(0 \leq i \leq n-l\). It is guaranteed that \(1 \leq l \leq n\).
inputFormat
The first line contains two integers \(n\) and \(l\) where \(n\) is the length of the string \(s\) and \(l\) is the length of the substring to consider.
The second line contains the string \(s\) consisting of lowercase English letters.
outputFormat
Output a single integer, the number of distinct contiguous substrings of length \(l\).
sample
6 3
abacab
4