Codeforces Round #426 (Div. 2)-B. The Festive Evening

来源:互联网 发布:中国网络资讯台无锡市 编辑:程序博客网 时间:2024/05/29 13:06

题目:

                                                                       B. The Festive Evening
                                                                       time limit per test
                                                                       1 second
                                                                       memory limit per test
                                                                       256 megabytes
                                                                       inputstandard input
                                                                       outputstandard output

It's the end of July – the time when a festive evening is held at Jelly Castle! Guests from all over the kingdom gather here to discuss new trends in the world of confectionery. Yet some of the things discussed here are not supposed to be disclosed to the general public: the information can cause discord in the kingdom of Sweetland in case it turns out to reach the wrong hands. So it's a necessity to not let any uninvited guests in.

There are 26 entrances in Jelly Castle, enumerated with uppercase English letters fromA toZ. Because of security measures, each guest is known to be assigned an entrance he should enter the castle through. The door of each entrance is opened right before the first guest's arrival and closed right after the arrival of the last guest that should enter the castle through this entrance. No two guests can enter the castle simultaneously.

For an entrance to be protected from possible intrusion, a candy guard should be assigned to it. There arek such guards in the castle, so if there are more thank opened doors, one of them is going to be left unguarded! Notice that a guard can't leave his post until the door he is assigned to is closed.

Slastyona had a suspicion that there could be uninvited guests at the evening. She knows the order in which the invited guests entered the castle, and wants you to help her check whether there was a moment when more thank doors were opened.

Input

Two integers are given in the first string: the number of guestsn and the number of guardsk (1 ≤ n ≤ 106,1 ≤ k ≤ 26).

In the second string, n uppercase English letterss1s2...sn are given, where si is the entrance used by thei-th guest.

Output

Output «YES» if at least one door was unguarded during some time, and «NO» otherwise.

You can output each letter in arbitrary case (upper or lower).

Examples
Input
5 1AABBB
Output
NO
Input
5 1ABABB
Output
YES
Note

In the first sample case, the door A is opened right before the first guest's arrival and closed when the second guest enters the castle. The door B is opened right before the arrival of the third guest, and closed after the fifth one arrives. One guard can handle both doors, as the first one is closed before the second one is opened.

In the second sample case, the door B is opened before the second guest's arrival, but the only guard can't leave the door A unattended, as there is still one more guest that should enter the castle through this door.

题意:有场宴会,共有n个人,k个保安。每个人通过一扇门进入城堡,每个保安看守一扇门直到所有要通过那扇门的宾客全部进入城堡才能离开,问存不存在有门没有保安看守的情况,有就YES,没有就NO

思路:没什么好说的,如果一扇门要走的宾客全部走了那个保安就可以去看别的门了

CODE:

#include<bits/stdc++.h>using namespace std;char s[1000005];int main(){        int n,k,cnt,a[26],b[26],i;        while(~scanf("%d%d%s",&n,&k,s)){                cnt=0;                for(i=0;i<26;i++) a[i]=b[i]=0;                for(i=0;s[i];i++) a[s[i]-'A']++;                for(i=0;s[i];i++){                        if(!b[s[i]-'A']){                                cnt++;                                b[s[i]-'A']=1;                        }                        if(cnt>k){                                puts("YES");                                break;                        }                        a[s[i]-'A']--;                        if(!a[s[i]-'A']){                                cnt--;                        }                }                if(i==n) puts("NO");        }    return 0;}



原创粉丝点击