WA了两个点,求大佬调,玄关
#include<bits/stdc++.h>
using namespace std;
int a[100001],n,k;
bool check(int len){
int cnt=0,tmp=1,pre=a[1];
for(int i=2;i<=n;i++){
if(a[i]==pre){
tmp++;
}else{
tmp=1;
pre=!pre;
}
if(tmp>len){
cnt++;
tmp=1;
pre=!pre;
}
}
return cnt<=k;
}
int main(){
cin>>n>>k;
string st;
cin>>st;
for(int i=1;i<=n;i++){
a[i]=(st[i-1]=='N'?1:0);
}
int l=1,r=n;
while(l<r){
int m=(l+r)>>1;
if(check(m))r=m;
else l=m+1;
}
cout<<r;
return 0;
}