博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Codeforces Round #426 (Div. 2) problem B
阅读量:7117 次
发布时间:2019-06-28

本文共 3168 字,大约阅读时间需要 10 分钟。

B. The Festive Evening
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard 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 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.

Input

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

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 1 AABBB
output
NO
input
5 1 ABABB
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.

题目大意:问是否有门没关,并且没人守卫的情况,如果有输出YES,否则输出NO。

思路:简单模拟。

1 #include
2 #include
3 using namespace std; 4 char num[1000050]; 5 int men[26]; 6 int flag[26]; 7 int main() 8 { 9 int n,k;10 cin>>n>>k;11 scanf("%s",num+1);12 for(int i=1;i<=n;i++){13 men[num[i]-'A']++;14 }15 int sum=0,now;16 for(int i=1;i<=n;i++){17 now=num[i]-'A';18 if(!flag[now]){19 flag[now]=1;20 sum++;21 if(sum>k){22 cout<<"YES"<

 

转载于:https://www.cnblogs.com/ISGuXing/p/7262455.html

你可能感兴趣的文章
iOS应用内语言切换功能
查看>>
如何写好一个UITableView
查看>>
上传伪技术~很多人都以为判断了后缀,判断了ContentType,判断了头文件就真的安全了。是吗?...
查看>>
NET Core-TagHelper实现分页标签
查看>>
Cesium原理篇:6 Renderer模块(1: Buffer)
查看>>
defered,promise回顾
查看>>
svn提交时出现很多乱文件怎么解决
查看>>
std::unique_lock<std::mutex> or std::lock_guard<std::mutex> C++11 区别
查看>>
SQL - ROW_NUMBER,Rank 添加序号列
查看>>
常见排序算法总结与实现(冒泡、插入、选择、希尔、堆排序、归并、快排)
查看>>
python3.x 和 python2.x关于 urllib的用法
查看>>
在pycharm中进行nosetests并输出测试报告
查看>>
树莓派:设置与软件安装
查看>>
JQuery日记_5.14 Sizzle选择器(七)
查看>>
debian8上安装pyspider - pyspider中文文档 - pyspider中文网
查看>>
【WaaCaa】一款开源科学作图/数据可视化工具 —— 诞生篇
查看>>
idea,eclipse创建多模块项目
查看>>
Tomcat中常见线程说明
查看>>
【iCore1S 双核心板_FPGA】例程八:触发器实验——触发器的使用
查看>>
Spring jdbcTemplate
查看>>