Codeforces Round #426 (Div. 2) problem B
B. The Festive Eveningtime limit per test1 second
memory limit per test256 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 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.
InputTwo 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.
OutputOutput «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).
Examplesinput5 1
AABBBoutputNOinput5 1
ABABBoutputYESNoteIn 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<iostream>
2 #include<stdio.h>
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"<<endl;
23 return 0;
24 }
25 }
26 men[now]--;
27 if(men[now]==0){
28 sum--;
29 }
30 }
31 cout<<"NO"<<endl;
32 return 0;
33 }
Codeforces Round #426 (Div. 2) problem B的更多相关文章
- CodeForces 834C - The Meaningless Game | Codeforces Round #426 (Div. 2)
/* CodeForces 834C - The Meaningless Game [ 分析,数学 ] | Codeforces Round #426 (Div. 2) 题意: 一对数字 a,b 能不 ...
- Codeforces Round #716 (Div. 2), problem: (B) AND 0, Sum Big位运算思维
& -- 位运算之一,有0则0 原题链接 Problem - 1514B - Codeforces 题目 Example input 2 2 2 100000 20 output 4 2267 ...
- Codeforces Round #243 (Div. 2) Problem B - Sereja and Mirroring 解读
http://codeforces.com/contest/426/problem/B 对称标题的意思大概是.应当指出的,当线数为奇数时,答案是线路本身的数 #include<iostream& ...
- Codeforces Round #426 (Div. 2)【A.枚举,B.思维,C,二分+数学】
A. The Useless Toy time limit per test:1 second memory limit per test:256 megabytes input:standard i ...
- Codeforces Round #753 (Div. 3), problem: (D) Blue-Red Permutation
还是看大佬的题解吧 CFRound#753(Div.3)A-E(后面的今天明天之内补) - 知乎 (zhihu.com) 传送门 Problem - D - Codeforces 题意 n个数字,n ...
- Codeforces Round #426 (Div. 2)
http://codeforces.com/contest/834 A. The Useless Toy 题意: <,>,^,v这4个箭头符号,每一个都可以通过其他及其本身逆时针或者顺时针 ...
- Codeforces Round #426 (Div. 2) A,B,C
A. The Useless Toy 题目链接:http://codeforces.com/contest/834/problem/A 思路: 水题 实现代码: #include<bits/st ...
- Codeforces Round #439 (Div. 2) Problem E (Codeforces 869E) - 暴力 - 随机化 - 二维树状数组 - 差分
Adieu l'ami. Koyomi is helping Oshino, an acquaintance of his, to take care of an open space around ...
- Codeforces Round #439 (Div. 2) Problem C (Codeforces 869C) - 组合数学
— This is not playing but duty as allies of justice, Nii-chan! — Not allies but justice itself, Onii ...
- Codeforces Round #439 (Div. 2) Problem B (Codeforces 869B)
Even if the world is full of counterfeits, I still regard it as wonderful. Pile up herbs and incense ...
随机推荐
- 图解Spark Graphx基于connectedComponents函数实现连通图底层原理
原创/朱季谦 第一次写这么长的graphx源码解读,还是比较晦涩,有较多不足之处,争取改进. 一.连通图说明 连通图是指图中的任意两个顶点之间都存在路径相连而组成的一个子图. 用一个图来说明,例如,下 ...
- 【NET 7.0、OpenGL ES】使用Silk.NET渲染MMD,并实时进行物理模拟。
有关mmd播放器,网上也有许多非常漂亮的实现,如 pmxeditor.saba.blender_mmd_tools等等.. 首先我想先介绍下我参考实现的仓库: sselecirPyM/Coocoo3D ...
- windows 网络模拟工具分享
[下载地址] Releases · jagt/clumsy · GitHub [介绍] 无需安装 无需篡改和代理 系统级限制,不针对单个程序,但可以针对单个IP 离线也可以限制,随停随用 界面简单 [ ...
- Oracle-判断表上存在高水位线
表上高水位线:通常一个新建的表,1个8K的数据块存放100行记录,若表上经常插入删除操作,造成表的水位线很高.下面从发现高水位线的办法,及解决高水位的方法说起: 1.发现存在高水位线的表:查看字典表u ...
- 若依框架的startPage( )函数怎么自动关联查询SQL语句?
Question Description 使用JAVA语言的若依框架的时候,发现只要使用了startPage()函数, 并不需要前端传递分页的数据,也不需要注解,就能完成分页功能.预判他应该是使用类似 ...
- 其它——Postman做接口测试
文章目录 一 介绍 二 下载安装 三 使用 四 批量接口测试(创建collections) 五 导出与导入同事的接口 5.1 导出 5.2 导入 一 介绍 在前后端分离开发时,后端工作人员完成系统接口 ...
- C#学习笔记---异常捕获和变量
异常捕获 使用异常捕获可以捕获出现异常的代码块,防止因为异常抛出造成的程序卡死的情况发生. try{}catch{}finally{}结构 //异常捕获 try { string str=Consol ...
- 循序渐进介绍基于CommunityToolkit.Mvvm 和HandyControl的WPF应用端开发(8) -- 使用Converter类实现内容的转义处理
在我们WPF应用端的时候,和WInform开发或者Vue前端开发一样,有时候也需要对内容进行转义处理,如把一些0,1数值转换为具体含义的文本信息,或者把一些布尔变量转换为是否等,都是常见的转换处理,本 ...
- 在 kubernetes 环境中实现 gRPC 负载均衡
前言 前段时间写过一篇 gRPC 的入门文章,在最后还留了一个坑没有填: 也就是 gRPC 的负载均衡问题,因为当时的业务请求量不算大,再加上公司没有对 Istio 这类服务网格比较熟悉的大牛,所以我 ...
- Building Bridges 题解
Building Bridges 题目大意 连接两根柱子 \(i,j\) 的代价是 \((h_i-h_j)^2+\sum\limits_{k=j+1}^{i-1}w_k\),连接具有传递性,求将 \( ...