Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <algorithm>
- #include <tuple>
- using namespace std;
- vector<int> zfunc(const string& s){
- vector<int> z(s.size());
- int first = 0;
- int last = 1;
- for (int i = 1; i < s.size(); ++i){
- if (i >= first && i < last && z[i - first] + i < last){
- z[i] = z[i - first];
- } else {
- z[i] = max(0, last - i);
- first = i;
- while (s[i + z[i]] == s[z[i]] && i + z[i] < s.size()){
- ++z[i];
- }
- last = i + z[i];
- }
- }
- return z;
- }
- int main() {
- string s;
- cin >> s;
- reverse(s.begin(), s.end());
- vector<int> z = zfunc(s);
- vector<int> z_val(s.size(), 1);
- z_val[0] = 2;
- for (int i = 0; i < s.size(); ++i){
- ++z_val[z[i]];
- }
- for (int i = s.size() - 1; i >= 0; --i){
- if (z_val[i] > 1){
- cout << i;
- return 0;
- }
- }
- return 0;
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement