A-Fried chicken want to lose weight of stringTime
limit:MS
Memory Limit:65535KB
64bit IO Format:SubmitStatusPracticenbut 1576
Description
Once upon a time, there was a string of long, long strings consisting of n lowercase letters.
One day when it was looking in the mirror, he felt too fat, so he wanted to lose weight. When you lose weight, you can constantly remove the first or last character.
After it wants to lose weight, for a slim factor m, the slim factor must contain ' a ', ' B ', ' C ' ... ' A ' +m-1 these characters, at least one of them.
Input
The first line has a number T, which indicates the number of groups. T <= 25
Next, each group has 2 integers n,m. N <= 1000 represents the length of the string, and M is the slim factor.
Then is a string of lowercase letters, the length of the string n <= 1000.
Output
Each row outputs a number that represents the minimum length to be evaluated for that group of data. We can only say "I am so fat!" for the small young ladies who cannot lose weight.
Sample Input
3CCBAA11 3ABBBBDBBBBC4 3abba
Sample Output
311I am SO fat!#include <cstdio> #include <iostream> #include <algorithm> #include <queue> #include <stack > #include <climits> #include <cstring> #include <cmath> #include <map> #include <set># Define INF 100000000using namespace Std;int n,m;char a[1005];int num[30];int main () {int t;cin >> t;while (t--) {cin &G t;> n >> m;scanf ("%s", a); int s = 0;int e = 0;memset (num,0,sizeof (num)); int cc = 0;int ans = inf;while (s < n) {W Hile (CC < m && e < N) {if (a[e]-' a ' < M && num[a[e]-' a '] = = 0) cc++;num[a[e]-' a '] ++;e++;} if ((E-s) < ans && cc >= m) ans = e-s;num[a[s]-' a ']--;if (a[s]-' a ' < M && num[a[s]-' a '] = = 0) {cc--; }s++;if ((E-s) < ans && cc >= m) ans = e-s;} if (ans = = INF) cout << "I am so fat!" << endl;elsecout << ans << endl;} return 0;}
The enumeration interval of the ruler extraction