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<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的更多相关文章

  1. CodeForces 834C - The Meaningless Game | Codeforces Round #426 (Div. 2)

    /* CodeForces 834C - The Meaningless Game [ 分析,数学 ] | Codeforces Round #426 (Div. 2) 题意: 一对数字 a,b 能不 ...

  2. 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 ...

  3. Codeforces Round #243 (Div. 2) Problem B - Sereja and Mirroring 解读

    http://codeforces.com/contest/426/problem/B 对称标题的意思大概是.应当指出的,当线数为奇数时,答案是线路本身的数 #include<iostream& ...

  4. 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 ...

  5. Codeforces Round #753 (Div. 3), problem: (D) Blue-Red Permutation

    还是看大佬的题解吧 CFRound#753(Div.3)A-E(后面的今天明天之内补) - 知乎 (zhihu.com) 传送门  Problem - D - Codeforces 题意 n个数字,n ...

  6. Codeforces Round #426 (Div. 2)

    http://codeforces.com/contest/834 A. The Useless Toy 题意: <,>,^,v这4个箭头符号,每一个都可以通过其他及其本身逆时针或者顺时针 ...

  7. Codeforces Round #426 (Div. 2) A,B,C

    A. The Useless Toy 题目链接:http://codeforces.com/contest/834/problem/A 思路: 水题 实现代码: #include<bits/st ...

  8. 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 ...

  9. 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 ...

  10. 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 ...

随机推荐

  1. Ubuntu Linux 更换国内源

    Ubuntu的官方源对于国内用户来说是比较慢的,可以将它的源换成国内的源,用起来就快很多了. # Ubuntu server 环境 ubuntu@ubuntu:~$ sudo su - [ sudo ...

  2. 扩展ABP的Webhook功能,推送数据到第三方接口(企业微信群、钉钉群等)

    前言 在上一篇文章[基于ASP.NET ZERO,开发SaaS版供应链管理系统]中有提到对Webhook功能的扩展改造,本文详细介绍一下具体过程. Webhook功能操作说明,请参见此文档链接:Web ...

  3. minio 支持object搜索方案

    minio支持上传时对object打标签,查询时可以根据标签做筛选.但是有ftp上传文件的需求,导致无法给object打标签.并且也不清楚minio对于根据标签的筛选性能如何,因此我们打算将objec ...

  4. redis单机、主从、哨兵、集群以及redisson分布式锁

    1.搭建集群 Linux系统的Redis各版本下载路径:https://download.redis.io/releases/,建议下载5.0以上的版本,下载后进行解压安装 (1)单机版 安装环境 y ...

  5. 大白话带你认识JVM(转)

    转自微信公众号(JavaGuide) 前言 如果在文中用词或者理解方面出现问题,欢迎指出.此文旨在提及而不深究,但会尽量效率地把知识点都抛出来 一.JVM的基本介绍 JVM 是 Java Virtua ...

  6. 文心一言 VS 讯飞星火 VS chatgpt (104)-- 算法导论10.1 2题

    二.用go语言,说明如何在一个数组 A[1..n]中实现两个栈,使得当两个栈的元素个数之和不为 n 时,两者都不会发生上溢.要求 PUSH 和 POP 操作的运行时间为 O(1). 文心一言: 在这个 ...

  7. 使用ensp搭建路由拓扑,并使用isis协议实现网络互通实操

    转载请注明出处: 1.通过拓扑搭建如下拓扑: 其中R7.R8为L1,R6为L1/2,R9为L2. 2.配置isis实现网络互通 R7配置如下: [Huawei]isis 1 [Huawei-isis- ...

  8. oracle多账套(用户)引用同一个账套的表或视图数据

    1.赋权限访问nbjf账套权限给到其他账套用户. grant select on nbjf.receivables to gzjf,hfjf,hfjy; 2.分别登陆 gzjf,hfjf,hfjy账套 ...

  9. WebGPU缓冲区更新最佳实践

    介绍 在WebGPU中,GPUBuffer是您将要操作的主要对象之一.它与GPUTextures一同代表了您的应用程序向GPU传递用于渲染的大部分数据.在WebGPU中,缓冲区用于顶点和索引数据.un ...

  10. python~windows自动化工具 uiautomation库

    微软提供了关于自动化操作PC端桌面应用程序的工具,官方描述为: Microsoft UI Automation is an accessibility framework that enables W ...