Codeforces Round #426 (Div. 2), problem: (B) The Festive Evening Solution In C/C++

#include<cstdio>

bool pd[26];
char s[1000007];
int n,k,size,last[26];

int main(){
scanf(“%d%d%s”,&n,&k,&s);
for (int i=0;i<n;++i) last[s[i]-‘A’]=i;
for (int i=0;i<n;++i){
if (!pd[s[i]-‘A’]) pd[s[i]-‘A’]=true,++size;
if (size>k){
printf(“YES”);
return 0;
}
if (i==last[s[i]-‘A’]) –size;
}
printf(“NO”);
}

(Visited 57 times, 1 visits today)

About the Author:

Leave A Comment