309100: CF1624D. Palindromes Coloring
Memory Limit:256 MB
Time Limit:2 S
Judge Style:Text Compare
Creator:
Submit:0
Solved:0
Description
Palindromes Coloring
题意翻译
多组询问。 将给出的长度为 $N$ 字符串划分成 $K$ 组,使每组字符串均为回文串,且这 $K$ 组字符串中最短的字符串尽可能长。题目描述
You have a string $ s $ consisting of lowercase Latin alphabet letters. You can color some letters in colors from $ 1 $ to $ k $ . 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, $ k $ strings will be created, $ i $ -th of them will contain all the characters colored in the color $ i $ , written in the order of their sequence in the string $ s $ . Your task is to color the characters of the string so that all the resulting $ k $ strings are palindromes, and the length of the shortest of these $ k $ strings is as large as possible. 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 $ t $ ( $ 1 \le t \le 10^4 $ ) — 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 integers $ n $ and $ k $ ( $ 1 \le k \le n \le 2 \cdot 10^5 $ ) — 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 $ s $ of length $ n $ consisting of lowercase letters of the Latin alphabet. It is guaranteed that the sum of n over all test cases does not exceed $ 2 \cdot 10^5 $ .
输出格式
For each set of input data, output a single integer — the maximum length of the shortest palindrome string that can be obtained.
输入输出样例
输入样例 #1
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
输出样例 #1
3
2
1
1
1
5
1
1
3
3