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

By | 2017-08-04T12:26:27+00:00 August 4th, 2017|Categories: C/C++, Programming|Tags: , , , , , , , |

#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"); }