Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- using lli = long long;
- const lli BP = 98765431;
- const int N = 1e2 + 10;
- char str[N + 10];
- lli pw[27];
- int len;
- int to_int(char a){
- return a - 'a' + 1;
- }
- int CountString(int l){
- lli hsh = 0;
- for(int i=1;i<=l-1;i++)
- hsh += pw[ to_int(str[i]) ];
- lli cnt = 0;
- map <lli, int> keep;
- for(int i=l;i<=len;i++){
- hsh += pw[ to_int(str[i]) ];
- cnt += keep[hsh];
- keep[hsh] ++;
- hsh -= pw[ to_int(str[i - l + 1]) ];
- }
- return cnt;
- }
- int main(){
- scanf("%s", str + 1);
- len = strlen(str + 1);
- pw[0] = 1;
- for(int i=1;i<=26;i++){
- pw[i] = pw[i - 1] * BP * i;
- }
- int ans = 0;
- for(int l=1;l<=len;l++){
- ans += CountString(l);
- }
- printf("%d", ans);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement