CF1883B.Chemistry
入门
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given a string s of length n, consisting of lowercase Latin letters, and an integer k.
You need to check if it is possible to remove exactly k characters from the string s in such a way that the remaining characters can be rearranged to form a palindrome. Note that you can reorder the remaining characters in any way.
A palindrome is a string that reads the same forwards and backwards. For example, the strings "z", "aaa", "aba", "abccba" are palindromes, while the strings "codeforces", "reality", "ab" are not.
给你一个长度为 n 的字符串 s,其中仅包含小写拉丁字母,以及一个整数 k。
你需要判断:是否能够恰好从字符串 s 中删除 k 个字符,使得剩余字符经过任意重排后可以构成一个回文串。
回文串是指正读和反读都相同的字符串。例如,字符串 "z"、"aaa"、"aba"、"abccba" 是回文串,而字符串 "codeforces"、"reality"、"ab" 不是回文串。
输入格式
Each test consists of multiple test cases. The first line contains a single integer t (1≤t≤104) — the number of the test cases. This is followed by their description.
The first line of each test case contains two integers n and k (0≤k<n≤105) — the length of the string s and the number of characters to be deleted.
The second line of each test case contains a string s of length n, consisting of lowercase Latin letters.
It is guaranteed that the sum of n over all test cases does not exceed 2⋅105.
每个测试包含多个测试用例。第一行包含一个整数 t(1≤t≤104),表示测试用例的数量。随后是各测试用例的描述。
每个测试用例的第一行包含两个整数 n 和 k(0≤k<n≤105),分别表示字符串 s 的长度以及需要删除的字符个数。
每个测试用例的第二行包含一个长度为 n 的字符串 s,由小写拉丁字母组成。
保证所有测试用例的 n 之和不超过 2⋅105。
输出格式
For each test case, output "YES" if it is possible to remove exactly k characters from the string s in such a way that the remaining characters can be rearranged to form a palindrome, and "NO" otherwise.
You can output the answer in any case (uppercase or lowercase). For example, the strings "yEs", "yes", "Yes", and "YES" will be recognized as positive answers.
对于每个测试用例,如果能够恰好从字符串 s 中删除 k 个字符,使得剩余字符可以重新排列成一个回文串,则输出 "YES";否则输出 "NO"。
你可以以任意大小写形式输出答案(大写或小写均可)。例如,字符串 "yEs"、"yes"、"Yes" 和 "YES" 均会被识别为肯定回答。
输入输出样例
输入#1
14 1 0 a 2 0 ab 2 1 ba 3 1 abb 3 2 abc 6 2 bacacd 6 2 fagbza 6 2 zwaafa 7 2 taagaak 14 3 ttrraakkttoorr 5 3 debdb 5 4 ecadc 5 3 debca 5 3 abaac
输出#1
YES NO YES YES YES YES NO NO YES YES YES YES NO YES
说明/提示
In the first test case, nothing can be removed, and the string "a" is a palindrome.
In the second test case, nothing can be removed, but the strings "ab" and "ba" are not palindromes.
In the third test case, any character can be removed, and the resulting string will be a palindrome.
In the fourth test case, one occurrence of the character "a" can be removed, resulting in the string "bb", which is a palindrome.
In the sixth test case, one occurrence of the characters "b" and "d" can be removed, resulting in the string "acac", which can be rearranged to the string "acca".
In the ninth test case, one occurrence of the characters "t" and "k" can be removed, resulting in the string "aagaa", which is a palindrome.
在第一个测试用例中,无法删除任何字符,字符串 “a” 本身就是一个回文串。
在第二个测试用例中,无法删除任何字符,但字符串 “ab” 和 “ba” 均不是回文串。
在第三个测试用例中,可以删除任意一个字符,所得字符串均为回文串。
在第四个测试用例中,可以删除一个字符 “a”,得到字符串 “bb”,它是一个回文串。
在第六个测试用例中,可以分别删除一个字符 “b” 和一个字符 “d”,得到字符串 “acac”,该字符串可重排为回文串 “acca”。
在第九个测试用例中,可以分别删除一个字符 “t” 和一个字符 “k”,得到字符串 “aagaa”,它是一个回文串。
输入解题思路,AI测评打分。不知道怎么写?