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 int MOD = 1e9 + 7;
- int p[3000], h[3000], 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;
- p[0] = 1;
- int n = s.size();
- 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] = (1ll * h[i - 1] + (1ll * (s[i] - 'a' + 1) * p[i]) % MOD) % MOD;
- }
- vector<long long> check;
- for (int i = 0; i < n; i++) {
- for (int j = i; j < n; j++) {
- if (j) {
- check.push_back((1ll * (h[j] - h[i - 1]) % MOD * p[n - i - 1]) % MOD);
- } else {
- check.push_back((1ll * h[j] * p[n - i - 1]) % MOD);
- }
- }
- }
- sort(check.begin(), check.end());
- check.erase(unique(check.begin(), check.end()), check.end());
- ans += (int)check.size();
- cout << ans;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement