Palindromes Coloring solution codeforces
You have a stringconsisting of lowercase Latin alphabet letters.
You can color some letters in colors fromto . It is not necessary to paint all the letters. But for each color, there must be a letter painted in that color.
Then you can swap any two symbols painted in the same color as many times as you want.
After that,strings will be created, -th of them will contain all the characters colored in the color , written in the order of their sequence in the string . Palindromes Coloring solution codeforces
Your task is to color the characters of the string so that all the resulting large as possible.strings are palindromes, and the length of the shortest of these strings is as
Read the note for the first test case of the example if you need a clarification.
Recall that a string is a palindrome if it reads the same way both from left to right and from right to left. For example, the strings abacaba, cccc, z and dxd are palindromes, but the strings abab and aaabaa — are not.
The first line of input data contains a single integer( ) — the number of input data sets in the test.
The descriptions of the input data sets follow.
The first line of the description of each input data set contains two integersand ( ) — the length of the string and the number of colors in which its letters can be painted. The second line of the description of each input data set contains a string of length consisting of lowercase letters of the Latin alphabet.
It is guaranteed that the sum of n over all test cases does not exceed.
For each set of input data, output a single integer — the maximum length of the shortest palindrome string that can be obtained.
10 8 2 bxyaxzay 6 3 aaaaaa 6 1 abcdef 6 6 abcdef 3 2 dxd 11 2 abcabcabcac 6 6 sipkic 7 2 eatoohd 3 1 llw 6 2 bfvfbv
output Palindromes Coloring solution codeforces
3 2 1 1 1 5 1 1 3 3
- In the first test case, bxyaxzay“, . We use indices in the string from to . The following coloring will work: (the letter z remained uncolored). After painting:
- swap two red characters (with the indices and ), we get ;
- swap two blue characters (with the indices and ), we get .
Now, for each of the two colors we write out the corresponding characters from left to right, we get two stringsand . Both of them are palindromes, the length of the shortest is . It can be shown that the greatest length of the shortest palindrome cannot be achieved.
- In the second set of input data, the following coloring is suitable: aaa, they are palindromes and their length is . . There is no need to swap characters. Both received strings are equal to
- In the third set of input data, you can color any character and take it into a string.
- In the fourth set of input data, you can color the th character in the color .
- In the fifth set of input data can be colored in each of the colors of one character.
- In the sixth set of input data, the following coloring is suitable: abcba and acbca. . Rearrange the characters so as to get the palindromes