#C8260. Minimum Swaps to Remove Unique Substrings

    ID: 52223 Type: Default 1000ms 256MiB

Minimum Swaps to Remove Unique Substrings

Minimum Swaps to Remove Unique Substrings

In this problem, you are given a string ( s ) and an integer ( k ). The task is to determine the minimum number of swaps required to remove all unique substrings of length ( k ) from the string ( s ). After careful observation, it turns out that the answer is equivalent to the number of distinct characters present in the string ( s ). For example, for ( s = \texttt{abcabc} ) and ( k = 3 ), the distinct characters are ( a, b, c ) so the answer is 3.

Note: Even though the parameter ( k ) is provided as part of the input, the optimal strategy relies solely on counting the distinct characters in ( s ).

inputFormat

The input is read from standard input (stdin). The first line contains an integer ( T ) representing the number of test cases. Each test case is described in a single line containing three elements: an integer ( n ) (the length of the string), an integer ( k ) (the length parameter for substrings), and the string ( s ). The elements are separated by spaces.

outputFormat

For each test case, output a single integer on a new line representing the minimum number of swaps required, which is equal to the number of distinct characters in ( s ). The output should be printed to standard output (stdout).## sample

1
6 3 abcabc
3

</p>