【CodeForces - 1038A 】Equality (思维水题,预处理字符串)

题干:

You are given a string ss of length nn, which consists only of the first kk letters of the Latin alphabet. All letters in string ss are uppercase.

A subsequence of string ss is a string that can be derived from ss 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 ss called good if the number of occurences of each of the first kkletters of the alphabet is the same.

Find the length of the longest good subsequence of ss.

Input

The first line of the input contains integers nn (1≤n≤1051≤n≤105) and kk (1≤k≤261≤k≤26).

The second line of the input contains the string ss of length nn. String ss only contains uppercase letters from 'A' to the kk-th letter of Latin alphabet.

Output

Print the only integer — the length of the longest good subsequence of string ss.

Examples

Input

9 3
ACAABCCAB

Output

6

Input

9 4
ABCABCABC

Output

0

Note

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 00.

解题报告:

    这题还是自己要读一遍,先解释了一遍子序列的概念,,这个很有往错误的方向诱导。。

    本来想着二分长度做,看数据量也刚刚好,但是做的时候发现根本不需要,其实就是很简单的一个预处理就ojbk了。

AC代码:

#include<bits/stdc++.h>using namespace std;
const int MAX = 2e5 + 5;
char s[MAX];
int bk[55];
int main()
{int n,k;cin>>n>>k;cin>>s;int len = strlen(s);for(int i = 0; i<len; i++) {bk[s[i]-'A']++;}int minn = 0x3f3f3f3f;for(int i = 0; i<k; i++) {minn = min(minn,bk[i]);}cout << minn*k << endl;return 0 ;
}//18:04 - 18:17

 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/441498.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

docker修改镜像的存储位置_云原生存储详解:容器存储与 K8s 存储卷(内含赠书福利)...

作者 | 阚俊宝 阿里巴巴技术专家参与文末留言互动&#xff0c;即有机会获得赠书福利&#xff01;导读&#xff1a;云原生存储详解系列文章将从云原生存储服务的概念、特点、需求、原理、使用及案例等方面&#xff0c;和大家一起探讨云原生存储技术新的机遇与挑战。本文为该系列…

vb简易计算机器程序,vb简易计算器源码

代码如下&#xff1a;/***Author:乌鸟heart*Version:1.0*/Dim IntX As Double 全局变量&#xff0c;用于存储计算的数值Dim IntOperation As Double 标记运算类型Dim isBegin As Boolean 标记是否已经给IntX赋值Public Sub Clear() 清空命令函数screen.Caption ""En…

【CodeForces - 1038B 】Non-Coprime Partition (构造,数组特征)

题干&#xff1a; Find out if it is possible to partition the first nn positive integers into two non-empty disjoint sets S1S1 and S2S2 such that: gcd(sum(S1),sum(S2))>1gcd(sum(S1),sum(S2))>1 Here sum(S)sum(S) denotes the sum of all elements presen…

计算机专业用锐龙笔记本,轻松应对工作挑战——ThinkPad T14 锐龙版,适合办公的笔记本电脑...

拥有一部适合办公的笔记本电脑&#xff0c;可以成为商务人士忙碌工作中强有力的支持。联想旗下的ThinkPad 系列笔记本电脑&#xff0c;一直秉持为高端商务人士服务的理念&#xff0c;以稳定、流畅、安全的使用体验得到广泛认可。其中的ThinkPad T14 锐龙版&#xff0c;更是有着…

python tabula 使用方法_Python中os.walk()的使用方法

os.walk()主要用来扫描某个指定目录下所包含的子目录和文件。这篇文章将通过几个简单的例子来说明python中os.walk()的使用方法。假设我们的test文件夹有如下的目录结构&#xff1a;我们首先用os.walk扫描test文件夹下所有的子目录和文件&#xff1a;# 使用os.walk扫描目录 imp…

【CodeForces - 1038C】Gambling (博弈问题,优先队列模拟,贪心)

题干&#xff1a; Two players A and B have a list of nn integers each. They both want to maximize the subtraction between their score and their opponents score. In one turn, a player can either add to his score any element from his list (assuming his list…

乐乐勇智能教育机器人有多少型号_【头条】协作机器人平台化趋势将会是柔性自动化的破局之道...

智能机器人商情微信公众号&#xff0c;关注中国智能机器人行业热点与发展趋势&#xff0c;打造快捷高效的行业资讯交互平台。更多精彩内容&#xff0c;您可以点击标题下方的蓝字关注我们。导语艾利特平台级CS系列协作机器人全新发布9月15日上海工博会第一天&#xff0c;艾利特机…

计算机毕设结束语致谢,毕业设计结束语和致谢

毕业设计结束语和致谢时间&#xff1a;2021-01-17 20:08:40 分类&#xff1a;小结范文 | 毕业论文致谢词范文 | Word文档下载毕业设计结束语和致谢导语&#xff1a;论文致谢应以简短的文字对课题研究与论文撰写过程中间直接给予帮助的人员(例如指导教师、答疑教师及其他人员)…

*【HDU - 2819】Swap(二分图匹配,输出路径)(待证明:是否是最少交换次数?)

题干&#xff1a; Given an N*N matrix with each entry equal to 0 or 1. You can swap any two rows or any two columns. Can you find a way to make all the diagonal entries equal to 1? Input There are several test cases in the input. The first line of each …

CSS中属性个属性值怎么区分,[CSS] 详细解释 @media 属性与 (max

前言现在 HTML5/CSS3 很流行罢&#xff0c;也是未来时代的趋势。在 HTML5 带来的许多实用功能之后&#xff0c;CSS3也同带来了一些牛逼哄哄的功能呢。动画 animation转化 transform过渡 translation尽快这已足够让我们兴奋&#xff0c;许多之前必须用 JS 或 JQ 写的效果用 CSS …

西门子精智和精简面板区别_西门子S7-1200的功能与特点,应用范围介绍

S7-1200是西门子公司新推出的一款面向离散自动化系统和独立自动化系统的低端PLC。S7-1200采用了模块化设计&#xff0c;具备强大的工艺功能&#xff0c;适用于多种场合&#xff0c;可以满足不同的自动化需求。S7-1200的定位处于原有的SIMATIC S7-200和SIMATIC S7-300之间&#…

【HDU - 1281 】棋盘游戏 (经典的二分图匹配,匈牙利算法,枚举删除顶点,必须边,关建边)

题干&#xff1a; 小希和Gardon在玩一个游戏&#xff1a;对一个N*M的棋盘&#xff0c;在格子里放尽量多的一些国际象棋里面的“车”&#xff0c;并且使得他们不能互相攻击&#xff0c;这当然很简单&#xff0c;但是Gardon限制了只有某些格子才可以放&#xff0c;小希还是很轻松…

eclipse提示方法已过时_提高效率,eclipse上你可能不知道的技巧

一张思维导图1、控制台(console )日志输出另保存经常会遇到这种情况&#xff0c;习惯性的清掉控制台上的输出日志&#xff0c;再然后发现刚才的日志居然还有用&#xff0c;不得不又重新调试一遍&#xff0c;为了解决这种“手贱”的问题&#xff0c;我在网上搜了一些资料&#x…

【CodeForces - 144B 】Meeting (暴力枚举,水题,计算几何)

题干&#xff1a; The Super Duper Secret Meeting of the Super Duper Secret Military Squad takes place in a Super Duper Secret Place. The place is an infinite plane with introduced Cartesian coordinate system. The meeting table is represented as a rectangle…

html中超链接使用_干货 | HTML中表格的使用方法

HTML中的表格是由表格的标签组成HTML中的表格是由标签用于定义表格的列&#xff0c;标签为又是标签来分割列&#xff0c;形成一个完整的表格。表格的标签组合关系为&#xff1a;我是单元格1我是单元格2表格中可以插入文本、图片、列表、段落、表单、水平线等任何html标签&#…

chrome插件中调用ajax,Chrome扩展程序中的Ajax调用无效

尝试在Chrome扩展程序中发送ajax请求。我已经确认请求返回200响应&#xff0c;它应该只是console.log来测试&#xff06;&#xff03;39;。我不确定这里是否存在异常问题&#xff1f;我已经阅读了Chrome扩展程序&#xff06;&#xff03;39; addListener&#xff06;&#xff0…

【CodeForces - 144C】Anagram Search(尺取,滑窗问题,处理字符串计数)

题干&#xff1a; A string t is called an anagram of the string s, if it is possible to rearrange letters in t so that it is identical to the string s. For example, the string "aab" is an anagram of the string "aba" and the string "…

互补品的交叉弹性系数_重庆事业单位综合备考:需求价格弹性和需求交叉价格弹性有何区别...

需求价格弹性 VS 需求交叉价格弹性一、需求价格弹性指某种商品随着价格的变化&#xff0c;该商品需求变化的程度大小(这里指的是同一种商品)。或者说&#xff0c;是需求变化相对于价格变化的敏感程度。假设&#xff1a;黄金、IPONE手机等商品降价50%&#xff0c;一定会大卖&…

esxi服务器与虚拟机时间不符,vsphere6.7-虚拟机与ESXI时间同步

ELF Format 笔记(十五)—— 符号哈希表ilocker:关注 Android 安全(新手) QQ: 2597294287 符号哈希表用于支援符号表的访问,能够提高符号搜索速度. 下表用于解释该哈希表的组织,但该格式并不属于 ELF 规范. ...AD域修改组策略如果我们的计算机加入AD域之后,修改安全策略时不能用…

朋友圈自动回复评论_微信新版,朋友圈可以表情包回复了!网友:评论区斗起来.jpg...

你们发现了吗&#xff1f;朋友圈可以发表情包评论了&#xff01;微信iOS版7.0.9正式版今天迎来更新支持发消息时可以引用之前的内容更令人惊喜的是不少网友都发现新版本还新增朋友圈自定义表情评论功能可以用表情包评论别人的朋友圈内容了&#xff01;轻触表情包还可以查看大图…