Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- typedef long long lli;
- const int N = 100 + 5;
- const int B = 1e9 + 7;
- lli enc[N];
- char str[N];
- int main(){
- scanf(" %s", str + 1);
- int len = strlen(str + 1);
- enc[0] = 1;
- for(int i = 1; i < 26; ++i){
- enc[i] = enc[i - 1] * B;
- }
- lli ans = 0;
- for(int i = 1; i <= len; ++i){
- map<lli, int> mp;
- lli hsh = 0;
- for(int j = 1; j <= i; ++j){
- hsh += enc[str[j] - 'a'];
- }
- ++mp[hsh];
- for(int j = i + 1; j <= len; ++j){
- hsh -= enc[str[j - i] - 'a'];
- hsh += enc[str[j] - 'a'];
- ans += mp[hsh];
- ++mp[hsh];
- }
- }
- cout << ans;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement