Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cstdio>
- #include <cstring>
- #include <vector>
- #include <algorithm>
- #include <map>
- using namespace std;
- char s[6000];
- long long ps[6000];
- long long h[6000];
- long long hcur[6000];
- int size = 0;
- int n;
- int main()
- {
- freopen("input.txt", "r", stdin);
- freopen("output.txt", "w", stdout);
- scanf("%s", s);
- n = strlen(s);
- const int p = 7;
- ps[0] = 1;
- for (int i = 1; i < n; ++i)
- ps[i] = ps[i - 1] * p;
- for (int i=0; i < n; ++i)
- {
- h[i] = (s[i]) * ps[i];
- if (i)
- h[i] += h[i-1];
- }
- int result = 0;
- for (int l = 1; l < n; ++l)
- {
- memset(hcur, 0, sizeof hcur);
- size = 0;
- for (int i = 0; i < n - l + 1; ++i)
- {
- long long cur_h = h[i + l - 1];
- if (i)
- cur_h -= h[i - 1];
- cur_h *= ps[n - i - 1];
- hcur[size++ ] = cur_h;
- }
- int current = 1;
- sort(hcur, hcur + size);
- for (int i = 1; i < size; ++i)
- {
- if (hcur[i] == hcur[i - 1])
- current++;
- else
- {
- if (current > 1)
- {
- result++;
- }
- current = 1;
- }
- }
- if (current > 1)
- result++;
- }
- printf("%d", result);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement