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 ...
随机推荐
- 深入理解Linux内核——内存管理(2)
提要:本系列文章主要参考MIT 6.828课程以及两本书籍<深入理解Linux内核> <深入Linux内核架构>对Linux内核内容进行总结. 内存管理的实现覆盖了多个领域: ...
- 在本地运行Kusto服务器
我喜欢Kusto (或商用版本 Azure Data Explorer,简称 ADX) 是大家可以有目共睹的,之前还专门写过这方面的书籍,请参考 大数据分析新玩法之Kusto宝典, 很可能在今年还会推 ...
- Python 基础面试第四弹
1. Python中常用的库有哪些,作用分别是什么 requests: requests 是一个用于发送 HTTP 请求的库,它提供了简单而优雅的 API,可以轻松地发送 GET.POST.PUT.D ...
- ptp 时钟同步
转载请注明出处: PTP(Precision Time Protocol)的功能可以帮助实现网络中各个节点的时钟同步,以提供更精确的时间参考. 作用: 时钟同步:通过PTP协议,在网络中不同节点之间实 ...
- jQuery下拉框级联实现
参考代码: //企业类别级联 function getCatalog(){ var name=document.getElementById("Lcata").value; var ...
- Solution -「营业」「ABC 170D」Not Divisible
Description Link. 给出一个长度为 \(n\) 的序列 \(a\),求 \(\sum_{i=1}^{n}[\forall j\in[1,i)\cup(i,n],a_{j}\nmid a ...
- Python爬虫IP代理池的建立和使用
写在前面建立Python爬虫IP代理池可以提高爬虫的稳定性和效率,可以有效避免IP被封锁或限制访问等问题. 下面是建立Python爬虫IP代理池的详细步骤和代码实现: 1. 获取代理IP我们可以从一些 ...
- jdk8环境变量
JAVA_HOME C:\Program Files\Java\jdk1.8.0_333 Path%JAVA_HOME%\bin%JAVA_HOME%\jre\bin CLASSPATH.%JAVA_ ...
- vue2中使用antv/G6节点内容可滚动的ER图
先举一个栗子: 效果链接:https://code.juejin.cn/pen/7226264955824930816 如果不会请移步到官网的栗子,请点击查看 狠人话不多,直接给大家上代码: 整体代码 ...
- 解决软件安装无法自定义文件夹,自动安装在C盘 (Windows系统)
其实就是软链接的简单应用 1.软件已经自动安装 2.完全退出当前软件 3.通过软件图标的属性找到其实际的安装目录 4.进入该软件的安装目录 5.将该软件整个剪切(你没有看错)到指定文件夹(自定义的安装 ...