日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

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

發布時間:2023/12/10 编程问答 23 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【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

?

總結

以上是生活随笔為你收集整理的【CodeForces - 1038A 】Equality (思维水题,预处理字符串)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。