Advertisement
Josif_tepe

Untitled

Jun 17th, 2023
960
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.38 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstring>
  3. #include <vector>
  4. #include <set>
  5. #include <map>
  6. #include <sstream>
  7. #include <cstdio>
  8. #include <algorithm>
  9. #include <stack>
  10. #include <queue>
  11. #include <cmath>
  12. #include <iomanip>
  13. #include <fstream>
  14. //#include <bits/stdc++.h>
  15. using namespace std;
  16. typedef long long ll;
  17. const int INF = (1 << 30);
  18. const ll inf = (1LL << 60LL);
  19. const int maxn = 1e5 + 5;
  20. const ll MOD = (ll)(1e9 + 7);
  21. int n;
  22. string s;
  23. map<char, int> cnt;
  24. int main(int argc, const char * argv[]) {
  25.     ios_base::sync_with_stdio(false);
  26.     cin >> n >> s;
  27.     vector<int> pos;
  28.     int k = 0, mnn;
  29.     for(int i = 0; i < n; i ++){
  30.         if(cnt.find(s[i]) == cnt.end()){
  31.             cnt[s[i]] = k;
  32.             ++k;
  33.         }
  34.         pos.push_back(cnt[s[i]]);
  35.     }
  36.     map<vector<int>, int> mapa;
  37.     vector<int> at(k);
  38.     ll ret = 0;
  39.     for(int i = 0; i < (int)pos.size(); i ++){
  40.         mapa[at] ++;
  41.         at[pos[i]] ++;
  42.         mnn = INF;
  43.         for(int j = 0; j < (int)at.size(); j ++){
  44.             mnn = min(mnn, at[j]);
  45.         }
  46.         for(int j = 0; j < (int)at.size(); j ++){
  47.             at[j] -= mnn;
  48.         }
  49.         ret += mapa[at];
  50.         ret %= MOD;
  51.     }
  52.     cout << ret << endl;
  53.     return 0;
  54. }
  55. /*
  56.  10 1
  57.  10 1 4 2 8 7 3 3 10 2
  58.  10
  59.  
  60.  5 1
  61.  2 4 2 3 5
  62.  4
  63.  */
  64. /*
  65.  10 1
  66.  10 1 4 2 8 7 3 3 10 2
  67.  10
  68.  
  69.  5 1
  70.  2 4 2 3 5
  71.  4
  72.  */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement