The enumeration interval of the ruler extraction

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.