Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- const int MAXN = 1e5 + 10;
- const int INF = 1e9 + 7;
- const double EPS = 1e-10;
- const double PI = acosl(-1);
- const int P = 41;
- const long long MOD = 1e9 + 23;
- long long p[10000], h[10000], ans;
- string s;
- int main() {
- //ifstream cin("input.txt");
- //ofstream cout("output.txt");
- ios_base::sync_with_stdio(false);
- cin.tie(0);
- cout.tie(0);
- cin >> s;
- int n = s.size();
- p[0] = 1;
- for (int i = 1; i <= n; i++) {
- p[i] = (1ll * p[i - 1] * P) % MOD;
- }
- h[0] = (s[0] - 'a' + 1);
- for (int i = 1; i < n; i++) {
- h[i] = (h[i - 1] + (s[i] - 'a' + 1) * p[i]) % MOD;
- }
- vector<long long> check;
- for (int i = 0; i < n; i++) {
- check.clear();
- for (int j = 0; j < n - i; j++) {
- long long ch;
- if (j) {
- ch = (h[j + i] - h[j - 1] + MOD) % MOD;
- } else {
- ch = (h[j + i] + MOD) % MOD;
- }
- ch = (ch * p[n - j - 1]) % MOD;
- check.push_back(ch);
- //if (j)
- // cout << s.substr(j, i + 1) << ' ' << ch << ' ' << h[i + j] << ' ' << h[j - 1] << ' ' << p[n - j - 1] << ' ' << i << ' ' << j << '\n';
- //else
- // cout << s.substr(j, i + 1) << ' ' << ch << ' ' << h[i + j] << ' ' << 0 << ' ' << p[n - j - 1] << ' ' << i << ' ' << j << '\n';
- }
- sort(check.begin(), check.end());
- check.erase(unique(check.begin(), check.end()), check.end());
- ans += check.size();
- }
- cout << ans;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement