-
Notifications
You must be signed in to change notification settings - Fork 0
/
C.cpp
42 lines (35 loc) · 764 Bytes
/
C.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define endl "\n"
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
int main(){
fast;
ll n;
cin>>n;
string s;
cin>>s;
set<char> se;
for(ll i=0;i<n;i++)
se.insert(s[i]);
ll sz = se.size();
map<char,ll> mp;
ll l=0,r=0, count=0, ans=n+1;
while(l<n){
while( r<n && count<sz ){
if(mp[s[r]]==0)
count++;
mp[s[r]]++;
r++;
}
if(r==n && count<sz)
break;
ans = min(ans,r-l);
if(mp[s[l]]==1)
count--;
mp[s[l]]--;
l++;
}
cout<<ans<<endl;
return 0;
}