https://i1.wp.com/eblogarithm.com/wp-content/uploads/2017/08/Codeforces-Round-426-Div-2-problem-B-The-Festive-Evening-Solution-In-CC1.png?fit=640%2C360

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 31 times, 1 visits today)



There are no comments

Add yours

Leave a Reply

%d bloggers like this: