• CodeForces-Zuhair and Strings(思维+枚举)


    Given a string ss of length nn and integer kk (1≤k≤n1≤k≤n). The string ss has a level xx, if xx is largest non-negative integer, such that it's possible to find in ss:

    • xx non-intersecting (non-overlapping) substrings of length kk,
    • all characters of these xx substrings are the same (i.e. each substring contains only one distinct character and this character is the same for all the substrings).

    A substring is a sequence of consecutive (adjacent) characters, it is defined by two integers ii and jj (1≤i≤j≤n1≤i≤j≤n), denoted as s[i…j]s[i…j] = "sisi+1…sjsisi+1…sj".

    For example, if k=2k=2, then:

    • the string "aabb" has level 11 (you can select substring "aa"),
    • the strings "zzzz" and "zzbzz" has level 22 (you can select two non-intersecting substrings "zz" in each of them),
    • the strings "abed" and "aca" have level 00 (you can't find at least one substring of the length k=2k=2 containing the only distinct character).

    Zuhair gave you the integer kk and the string ss of length nn. You need to find xx, the level of the string ss.

    Input

    The first line contains two integers nn and kk (1≤k≤n≤2⋅1051≤k≤n≤2⋅105) — the length of the string and the value of kk.

    The second line contains the string ss of length nn consisting only of lowercase Latin letters.

    Output

    Print a single integer xx — the level of the string.

    Examples

    Input

    8 2
    aaacaabb
    

    Output

    2
    

    Input

    2 1
    ab
    

    Output

    1
    

    Input

    4 2
    abab
    

    Output

    0
    

    Note

    In the first example, we can select 22 non-intersecting substrings consisting of letter 'a': "(aa)ac(aa)bb", so the level is 22.

    In the second example, we can select either substring "a" or "b" to get the answer 11.

    思路:从'a'-'z'枚举即可

    代码:

    #include<cstring>
    #include<algorithm>
    #include<cstdio>
    #include<iostream>
    
    using namespace std;
    char a[200005];
    
    int main()
    {
    	
    	int n,k;
    	cin>>n>>k;
    	getchar();
    	scanf("%s",a);
    	int len=strlen(a);
    	int maxn=0;
    	for(char  t='a';t<='z';t++)
    	{
    		
    		
    		int sum=0;
    		int ss=0;
    		for(int j=0;j<len;j++)
    		{
    			if(a[j]!=t)
    			{
    				sum+=ss/k;
    				ss=0;
    			}
    			else
    			{
    				ss++;
    			}
    		}
    		sum+=ss/k;
    		maxn=max(sum,maxn);
    	}
    	cout<<maxn<<endl;
    	
    	
    	return 0;
    }
  • 相关阅读:
    使非标准 Win32 控件或自画控件也具有 Windows XP 的界面风格
    MapInfo格式到ArcInfo格式的转换
    DICOM医学图像文件格式
    香港身份证
    Cheap Tricks: Let's Talk About METADATA TypeLibs
    ASP中使用ADO访问数据源
    DirectX 9 编程 DirectX窗口
    3DES Source Code
    OLEDB Resource(Session) Pooling (在Ado开发中使用连接池)
    《仙剑奇侠传4》仙剑问答全答案
  • 原文地址:https://www.cnblogs.com/Staceyacm/p/10781837.html
Copyright © 2020-2023  润新知