fork download
  1. #include <bits/stdc++.h>
  2. #define fastio() ios_base::sync_with_stdio(false); cin.tie(NULL);
  3. using namespace std;
  4.  
  5. #define int long long
  6. #define vi vector<int>
  7.  
  8. void solve() {
  9. int n;
  10. string s;
  11. cin >>n>>s;
  12. int ans=0;
  13. for(int i=0;i<n;i++) {
  14. int freq[10]={};
  15. int dis=0,mxx=0;
  16.  
  17. for(int j=i;j<n&&j<i+100;j++){
  18. int d =s[j]-'0';
  19.  
  20. if(freq[d]==0)dis++;
  21.  
  22. freq[d]++;
  23. mxx=max(mxx,freq[d]);
  24.  
  25. if(mxx<=dis)ans++;
  26. }
  27. }
  28.  
  29. cout<<ans<<'\n';
  30. }
  31.  
  32.  
  33. signed main() {
  34. fastio();
  35.  
  36. int t=1;
  37. cin>>t;
  38. while (t--)
  39. {
  40. solve();
  41. }
  42.  
  43. return 0;
  44. }
Success #stdin #stdout 0s 5316KB
stdin
7
1
7
2
77
4
1010
5
01100
6
399996
5
23456
18
789987887987998798
stdout
1
2
10
12
10
15
106