【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 ACAABCCABOutput
6Input
9 4 ABCABCABCOutput
0Note
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.
解題報告:
? ? 這題還是自己要讀一遍,先解釋了一遍子序列的概念,,這個很有往錯誤的方向誘導(dǎo)。。
? ? 本來想著二分長度做,看數(shù)據(jù)量也剛剛好,但是做的時候發(fā)現(xiàn)根本不需要,其實就是很簡單的一個預(yù)處理就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?
總結(jié)
以上是生活随笔為你收集整理的【CodeForces - 1038A 】Equality (思维水题,预处理字符串)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 光大信用卡查询进度平台 总有一种途径适合
- 下一篇: 牛不过三的定律是真的吗?2021年会是牛