Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- typedef long long ll;
- typedef long double ld;
- //#define int ll
- #define double ld
- #define _FastIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
- #define pii pair<int , int>
- #define pb emplace_back
- //#define endl '\n'
- #define all(x) x.begin() , x.end()
- #define rall(x) x.rbegin() , x.rend()
- #define F first
- #define S second
- const int mod = 1e9 + 7;
- const int MAXX = 1e5 + 5;
- int t , n;
- string s;
- int a[MAXX];
- int cnt[11][MAXX];
- int m[15];
- int c[15];
- int main()
- {
- _FastIO;
- cin >> t;
- while(t--){
- cin >> n;
- cin >> s;
- for(int i = 0; i < n; i++){
- a[i] = int(s[i]) - 48;
- }
- int ans = n;
- int k = 2;
- int l = min(n , 100);
- while(k <= l){
- int p = 0;
- for(int i = 0; i < k; i++){
- if(!m[a[i]])
- p++;
- m[a[i]]++;
- bool ok = true;
- for(int j = 0; j < 10; j++){
- if(m[j] > p){
- ok = false;
- break;
- }
- }
- if(ok){
- ans++;
- }
- }
- for(int i = k; i < n; i++){
- m[a[i - k]]--;
- if(!m[a[i - k]])
- p--;
- if(!m[a[i]])
- p++;
- m[a[i]]++;
- bool ok = true;
- for(int j = 0; j < 10; j++){
- if(m[j] > p){
- ok = false;
- break;
- }
- }
- if(ok)
- ans++;
- }
- k++;
- for(int i = 0; i < 10; i++){
- m[i] = 0;
- }
- }
- cout << ans << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement