The Festive Evening map
来源:互联网 发布:淘宝买家要求延迟发货 编辑:程序博客网 时间:2024/05/23 02:00
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 from A to Z. 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 are k such guards in the castle, so if there are more than k 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 than k doors were opened.
Two integers are given in the first string: the number of guests n and the number of guards k (1 ≤ n ≤ 106, 1 ≤ k ≤ 26).
In the second string, n uppercase English letters s1s2... sn are given, where si is the entrance used by the i-th guest.
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).
input
5 1
AABBB
output
NO
input
5 1
ABABB
output
YES
#include<cstdio>#include<iostream>#include<cstring>#include<string>#include<map>using namespace std;int main(){ int n,k; map<char,int> m; map<char,int> v; char str[1000005]; while(~scanf("%d%d",&n,&k)) { int cnt=1,tag=0; m.clear();v.clear(); memset(str,0,sizeof(str)); scanf("%s",str); for(int i=0;i<n;i++) m[str[i]]++; m[str[0]]--;v[str[0]]=1; for(int i=1;i<n;i++) { if(!m[str[i-1]]) tag++; if(v[str[i]]==0) { v[str[i]]=1; cnt++; if(tag) {cnt--;tag--;} } m[str[i]]--; } if(cnt>k) printf("YES\n"); else printf("NO\n"); } return 0;}
- The Festive Evening map
- Codeforces834B The Festive Evening
- CF834B-The Festive Evening
- The Festive Evening
- The Festive Evening
- The Festive Evening (Codeforces
- cf The Festive Evening(水)
- The Festive Evening(思维题)
- 守卫问题The Festive Evening
- CodeFroces 834B. The Festive Evening(暴力)
- Codeforces 834B-The Festive Evening
- 【CodeForces】426Div2 B The Festive Evening
- Codeforces Round 834B-The Festive Evening
- Codeforces 834 B The Festive Evening
- CodeForces #426 div2 B The Festive Evening
- CodeForces 834B The Festive Evening
- The Festive Evening (思维题目)
- CF 834B-The Festive Evening
- 如何使用阿里云虚拟主机搭建博客(三)设置篇
- Leetcode算法学习日志 -240 Search a 2D Matrix 2
- DATE_ADD() 与 DATE_SUB() 日期的加法与減法
- 2985_数字组合
- Android----------Recyclerview设置点击事件
- The Festive Evening map
- 引用---常引用型返回值
- 解决安装ros时出现的Depends: ros-indigo-simulators依赖问题
- 程序中的逻辑运算符:&&
- html中的表格元素
- 成为一名更好前端开发人员的9个技巧
- Linux Mint 18.2 gedit中文乱码问题
- javascript原型和闭包(15)——闭包
- tensorflow:用dynamic_rnn处理不定长序列,对序列做padding处理