Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <algorithm>
- #include <vector>
- #include <string>
- void get_z_func(std::string s, int n, std::vector<int>& z, int shift)
- {
- z[0] = n - shift;
- for (int i = 1, l = 0, r = 0; i < n - shift; ++i)
- {
- if (i <= r)
- z[i] = std::min(r - i + 1, z[i - l]);
- while (i + z[i] < n && s[i + z[i] + shift] == s[z[i] + shift])
- ++z[i];
- if (i + z[i] - 1 > r)
- {
- l = i;
- r = i + z[i] - 1;
- }
- }
- }
- int max_repeating_substr(std::string s)
- {
- int n = s.length();
- int k_max = 1;
- for (int i = 0; i < n; ++i)
- {
- std::vector<int> z(n - i, 0);
- get_z_func(s, n, z, i);
- for (int curr_n, k, j = 1; j < n - i; ++j)
- {
- curr_n = z[j] + j - ((z[j] + j) % j);
- k = curr_n / j;
- if (k_max < k)
- k_max = k;
- }
- }
- return k_max;
- }
- int main()
- {
- std::string s;
- std::cin >> s;
- std::cout << max_repeating_substr(s);
- return 0;
- }
Add Comment
Please, Sign In to add comment