#C6769. Count Distinct Substrings of Fixed Length
Count Distinct Substrings of Fixed Length
Count Distinct Substrings of Fixed Length
You are given a string (S) and an integer (K). Your task is to compute the number of distinct non-empty substrings of (S) that have exactly length (K). If (K) is greater than the length of (S), output (-1).
For example, if (S = \texttt{abcabc}) and (K = 3), the distinct substrings of length 3 are (\texttt{abc}), (\texttt{bca}), and (\texttt{cab}), so the answer is 3.
The problem can be summarized by the formula: [ \text{result} = \begin{cases} -1 & \text{if } K > |S|, \ #{ S[i:i+K] : 0 \le i \le |S|-K } & \text{otherwise.} \end{cases} ]
inputFormat
The input is read from standard input (stdin) and consists of a single line containing a string (S) and an integer (K) separated by whitespace. (S) will contain no spaces.
outputFormat
Output a single integer to standard output (stdout) representing the number of distinct substrings of length (K) in (S), or (-1) if (K) is greater than the length of (S).## sample
abcabc 3
3