Josif_tepe

Untitled

Feb 4th, 2026
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.06 KB | None | 0 0
  1. #include <iostream>
  2. #include <set>
  3. #include <map>
  4. using namespace std;
  5.  
  6. const int MOD = 1e9 + 7;
  7.  
  8. int main() {
  9.     ios_base::sync_with_stdio(false);
  10.    
  11.     int n;
  12.     cin >> n;
  13.    
  14.     string s;
  15.     cin >> s;
  16.    
  17.     set<char> st;
  18.     for(int i = 0; i < n; i++) {
  19.         st.insert(s[i]);
  20.     }
  21.    
  22.     int K = (int) st.size();
  23.    
  24.     int res = 0;
  25.     for(int i = 0; i < n; i++) {
  26.         map<char, int> m;
  27.         string p = "";
  28.         for(int j = i; j < n; j++) {
  29.             m[s[j]]++;
  30.             p += s[j];
  31.             if((j - i + 1) % K == 0) {
  32.                 int cnt = (j - i + 1) / K;
  33.                 bool ok = true;
  34.                 for(pair<char, int> mp: m) {
  35.                     if(mp.second != cnt) {
  36.                         ok = false;
  37.                         break;
  38.                     }
  39.                 }
  40.                 if(ok) {
  41.                     res++;
  42.                     res %= MOD;
  43.                 }
  44.             }
  45.            
  46.         }
  47.     }
  48.    
  49.     cout << res << endl;
  50.    
  51.    
  52.    
  53.     return 0;
  54. }
  55.  
Advertisement
Add Comment
Please, Sign In to add comment