0
点赞
收藏
分享

微信扫一扫

Codeforces Round #533 (Div. 2) B. Zuhair and Strings

金刚豆 2023-02-17 阅读 128


                                                                        B. Zuhair and Strings

 

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

  • x non-intersecting (non-overlapping) substrings of length k,
  • all characters of these x 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 j (1≤i≤j≤n), denoted as s[i…j]= "sisi+1…sj".

For example, if k=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=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⋅10^5) — 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 x — the level of the string.

Examples

input

Copy

8 2
aaacaabb

output

Copy

2

input

Copy

2 1
ab

output

Copy

1

input

Copy

4 2
abab

output

Copy

0

Note

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

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

 

题解 : 找 长度为 k 的最大子串的个数,所有子串都是相同字符 .

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <stack>
#include <queue>
#define Swap(a,b) a ^= b ^= a ^= b
using namespace std ;
const int MAX = 200005;
const int inf = 0xffffff;
typedef long long LL;
LL gcd(LL a , LL b)
{
return b== 0 ? a : gcd(b,a%b) ;
}
char s[MAX];
int book[26] ;
int minn = 0xfffff;
int main()
{
int n , k ;
int i , j ;
int ans = 0 ;
int x ;
cin >> n >>k ;
cin >> s ;

for( i = 0 ; i <n ;i++)
{
for( j = i+1 ; j<i+k &&j<n; j++ )
{
if(s[i]!=s[j])
break ;
}
if(j == i+k )

book[s[i]-'a']++ ;
i = j - 1;

}
for(int i = 0 ; i <26 ; i++ )
{
if(ans < book[i])
{
ans = book[i] ;
}
}
cout<<ans<<endl;



return 0 ;
}

 

 

举报

相关推荐

0 条评论