Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define ull unsigned long long
- using namespace std;
- const int N = 1e5 + 3;
- const ull base = 31;
- ull h[N], b[N];
- ull get(int i, int j) {
- return (h[j] - ((i > 0) ? h[i - 1] * b[j - i + 1] : 0));
- }
- int main() {
- string s;
- cin >> s;
- int n = s.size();
- b[0] = 1;
- for (int i = 1; i <= n; ++i) {
- b[i] = b[i - 1] * base;
- }
- h[0] = s[0];
- for (int i = 1; i < n; ++i) {
- h[i] = (h[i - 1] * base + s[i]);
- }
- set<ull> d;
- for (int len = 1; len <= n; ++len) {
- for (int i = 0, j = len - 1; j < n; ++i, ++j) {
- d.insert(get(i, j));
- }
- }
- cout << d.size();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement