!Codeforces Round #364 (Div. 2) C. They Are Everywhere

Posted wyh447154317

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了!Codeforces Round #364 (Div. 2) C. They Are Everywhere相关的知识,希望对你有一定的参考价值。

https://codeforces.com/contest/701/problem/C

 

 

binary search strings two pointers

 

#include<bits/stdc++.h>
using namespace std;
const int N=1e5+5;
char s[N];

int main(){
    int n,tot=0;
    cin>>n;
    getchar();
    map<char,int>cnt;
    for(int i=1;i<=n;i++){
    s[i]=getchar();
    if(!cnt[s[i]])tot++;
    cnt[s[i]]++;}
    cnt.clear();
    int r=0,ntot=0,ans=1e5+5,flag=0;
    for(int i=1;i<=n;i++){
    //    if(i!=1&&cnt[s[i-1]]==1) ntot--,cnt[s[i-1]]--;
    if(i!=1){
        if(cnt[s[i-1]]==1)ntot--;
        cnt[s[i-1]]--;
    }
        while(ntot<tot){
            if(r==n)break;
            r++;
            if(!cnt[s[r]])ntot++;
            cnt[s[r]]++;
        //    if(r==n){flag=1;break;    }
        }
        if(ntot==tot)ans=min(ans,r-i+1);
        //if(flag)break;
    }
    cout<<ans;
    return 0;
}

以上是关于!Codeforces Round #364 (Div. 2) C. They Are Everywhere的主要内容,如果未能解决你的问题,请参考以下文章

codeforces 700a//As Fast As Possible// Codeforces Round #364(Div. 1)

Educational Codeforces Round 24 D

Codeforces Round #797 (Div. 3) D, E, F, G题题解

Codeforces Round #402 (Div. 2) D

Codeforces Round #408 (Div. 2) D

Codeforces Round #390 (Div. 2) D