Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- int main() {
- string s;
- ios_base::sync_with_stdio(false);
- getline(cin, s);
- int k = 1;
- for (int i = 0; i < s.size(); ++i) {
- int n = (int)s.size();
- vector<int> z(s.size(), 0);
- int l, r = 0;
- for (int i = 1; i < n; ++i) {
- if (i <= r)
- z[i] = min(r - i + 1, z[i - l]);
- while (i + z[i] < n && s[z[i]] == s[i + z[i]])
- ++z[i];
- if (i + z[i] - 1 > r) {
- l = i;
- r = i + z[i] - 1;
- }
- }
- for (int i = 1; i < n; ++i) {
- if ((i + z[i]) % i == 0) {
- k = max(k, (i + z[i]) / i);
- }
- }
- s.erase(s.begin());
- }
- cout << k << '\n';
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement