Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <set>
- #include <map>
- #include <vector>
- using namespace std;
- const int INF = 2e9;
- const int MOD = 1e9 + 7;
- int main() {
- ios_base::sync_with_stdio(false);
- int n;
- cin >> n;
- string s;
- cin >> s;
- vector<int> pos;
- map<char, int> cnt;
- int k = 0;
- for(int i = 0; i < n; i++) {
- if(cnt.find(s[i]) == cnt.end()) {
- cnt[s[i]] = k;
- ++k;
- }
- pos.push_back(cnt[s[i]]);
- }
- vector<int> at(k, 0);
- map<vector<int>, int> mapa;
- int res = 0;
- for(int i = 0; i < n; i++) {
- mapa[at]++;
- at[pos[i]]++;
- int min_value = INF;
- for(int j = 0; j < k; j++) {
- min_value = min(min_value, at[j]);
- }
- for(int j = 0; j < k; j++) {
- at[j] -= min_value;
- }
- res += mapa[at];
- res %= MOD;
- }
- cout << res << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment