Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- //#define debug(...) printf( __VA_ARGS__ )
- #define debug(...) /****nothing****/
- #define ll long long
- #define ull unsigned long long
- #define pb push_back
- #define mem(arr,val) memset(arr,val,sizeof(arr))
- #define mp make_pair
- #define pii pair<int,int>
- #define F first
- #define S second
- #define sz(x) (int)(x).size()
- #define nopos string::npos
- #define fr(i,a,b) for(i=a;i<=b;i++)
- #define frn(i,a,b) for(i=a;i>=b;i--)
- int n,sz,cnt,i,j;
- set<char> data;
- char str[123456];
- int main()
- {
- while(cin>>n)
- {
- scanf("%s",str+1);
- int ans=n+1;
- data.clear();
- for(i=1;i<=n;i++)
- data.insert(str[i]);
- cnt=data.size(); // all types of pokemon in string str
- for(i=1;i<=n;i++)
- {
- int low=i-1 , high=n+1;
- while(high-low>1)
- {
- int mid=(high+low)/2;
- data.clear();
- for(j=i;j<=mid;j++)
- data.insert(str[j]); //to evaluate : how many distinct character from i index to mid index
- if(data.size()>=cnt)
- high=mid;
- else
- low=mid;
- }
- if(high!=n+1) // we got a segment from i to high where number of distinct characters are equal to cnt
- {
- ans=min(ans,high-i+1);
- }
- }
- cout<<ans<<'\n';
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement