Advertisement
LEGEND2004

sd

Nov 12th, 2022
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.90 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. typedef long long ll;
  5. typedef long double ld;
  6. //#define int ll
  7. #define double ld
  8. #define _FastIO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
  9. #define pii pair<int , int>
  10. #define pb emplace_back
  11. //#define endl '\n'
  12. #define all(x) x.begin() , x.end()
  13. #define rall(x) x.rbegin() , x.rend()
  14. #define F first
  15. #define S second
  16. const int mod = 1e9 + 7;
  17. const int MAXX = 1e5 + 5;
  18.  
  19. int t , n;
  20. string s;
  21. int a[MAXX];
  22. int cnt[11][MAXX];
  23. int m[15];
  24. int c[15];
  25.  
  26. int main()
  27. {
  28. _FastIO;
  29. cin >> t;
  30. while(t--){
  31. cin >> n;
  32. cin >> s;
  33. for(int i = 0; i < n; i++){
  34. a[i] = int(s[i]) - 48;
  35. }
  36. int ans = n;
  37. int k = 2;
  38. int l = min(n , 100);
  39. while(k <= l){
  40. int p = 0;
  41. for(int i = 0; i < k; i++){
  42. if(!m[a[i]])
  43. p++;
  44. m[a[i]]++;
  45. bool ok = true;
  46. for(int j = 0; j < 10; j++){
  47. if(m[j] > p){
  48. ok = false;
  49. break;
  50. }
  51. }
  52. if(ok){
  53. ans++;
  54. }
  55. }
  56. for(int i = k; i < n; i++){
  57. m[a[i - k]]--;
  58. if(!m[a[i - k]])
  59. p--;
  60. if(!m[a[i]])
  61. p++;
  62. m[a[i]]++;
  63. bool ok = true;
  64. for(int j = 0; j < 10; j++){
  65. if(m[j] > p){
  66. ok = false;
  67. break;
  68. }
  69. }
  70. if(ok)
  71. ans++;
  72. }
  73. k++;
  74. for(int i = 0; i < 10; i++){
  75. m[i] = 0;
  76. }
  77. }
  78. cout << ans << endl;
  79. }
  80. return 0;
  81. }
  82.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement