CF1038A.Equality
入门
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given a string s of length n, which consists only of the first k letters of the Latin alphabet. All letters in string s are uppercase.
A subsequence of string s is a string that can be derived from s by deleting some of its symbols without changing the order of the remaining symbols. For example, "ADE" and "BD" are subsequences of "ABCDE", but "DEA" is not.
A subsequence of s called good if the number of occurences of each of the first k letters of the alphabet is the same.
Find the length of the longest good subsequence of s.
给你一个长度为 n 的字符串 s,它仅由拉丁字母表的前 k 个字母组成。字符串 s 中的所有字母均为大写。
字符串 s 的一个子序列是指通过删除 s 中的某些字符(不改变剩余字符的相对顺序)所得到的字符串。例如,“ADE”和“BD”都是“ABCDE”的子序列,但“DEA”不是。
若字符串 s 的一个子序列中,拉丁字母表前 k 个字母各自出现的次数均相等,则称该子序列为好子序列(good subsequence)。
请找出 s 的最长好子序列的长度。
输入格式
The first line of the input contains integers n (1≤n≤105) and k (1≤k≤26).
The second line of the input contains the string s of length n. String s only contains uppercase letters from 'A' to the k-th letter of Latin alphabet.
输入的第一行包含两个整数 n(1≤n≤105)和 k(1≤k≤26)。
输入的第二行包含一个长度为 n 的字符串 s。字符串 s 仅由从 'A' 开始的拉丁字母表的前 k 个大写字母组成。
输出格式
Print the only integer — the length of the longest good subsequence of string s.
输出唯一的整数——字符串 s 的最长“好”子序列的长度。
输入输出样例
输入#1
9 3 ACAABCCAB
输出#1
6
输入#2
9 4 ABCABCABC
输出#2
0
说明/提示
In the first example, "ACBCAB" ("ACAABCCAB") is one of the subsequences that has the same frequency of 'A', 'B' and 'C'. Subsequence "CAB" also has the same frequency of these letters, but doesn't have the maximum possible length.
In the second example, none of the subsequences can have 'D', hence the answer is 0.
在第一个例子中,“ACBCAB”(“ACAABCCAB”)是满足字母 'A'、'B' 和 'C' 出现频率相同的子序列之一。子序列 “CAB” 也满足这些字母频率相同,但其长度并非最大可能值。
在第二个例子中,没有任何子序列能包含字母 'D',因此答案为 0。
输入解题思路,AI测评打分。不知道怎么写?