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

本文介绍了一种算法,用于在一个给定长度的字符串中找到最大的非负整数级别,该级别表示可以找到的非交叠子串数量,这些子串长度相同且由单一字符组成。通过枚举所有可能的字符并计算满足条件的子串,最终确定字符串的级别。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

black-hole6

你的鼓励将是我创作的动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值