【Codeforces Round #426 (Div. 2) B】The Festive Evening

Link:http://codeforces.com/contest/834/problem/B

Description

Solution

模拟水题;
注意一个字母单个出现的时候,结束和开始一起写;

NumberOf WA


Reviw


Code

#include <bits/stdc++.h>
using namespace std;
#define int long long

int n,k;
char s[(int) 1e6+100];
int rest[500],now[500];

main(){
    scanf("%lld%lld",&n,&k);
    scanf("%s",s+1);
    for (int i = 1;i <= n;i++)
        rest[s[i]]++;
    int temp = 0;
    for (int i = 1;i <= n;i++){
        now[s[i]]++;
        if (now[s[i]]==1){
            temp++;
            if (temp>k){
                return puts("YES"),0;
            }
        }
        if (now[s[i]]==rest[s[i]]){
            temp--;
        }
    }
    puts("NO");
    return 0;
}
posted @ 2017-10-04 18:44  AWCXV  阅读(104)  评论(0编辑  收藏  举报