Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <vector>
- #include <array>
- #include <iostream>
- #include <string>
- #include <algorithm>
- #include <utility>
- const int MAXN = 500000;
- std::array<char, MAXN> s;
- std::array<int, MAXN> rad;
- int main() {
- std::string str;
- std::cin >> str;
- int n = str.size();
- for (int i = 0; i < n; i++)
- s[i] = str[i];
- int ansL = 0;
- int ansR = 0;
- for (int z = 0; z < 2; ++z) {
- int l = 0, r = -1;
- for (int i = 0; i < n; ++i) {
- if (i > r) {
- rad[i] = 1 - z;
- }
- else {
- rad[i] = std::min(rad[l + r - i + z], r - i + z);
- }
- while (rad[i] + z <= i && i + rad[i] < n && s[i + rad[i]] == s[i - rad[i] - z]) {
- ++rad[i];
- }
- if (i + rad[i] - z > r) {
- l = i - rad[i] + (1 - z);
- r = i + rad[i] - 1;
- }
- if (ansR - ansL < i + rad[i] - (i - rad[i] - z) - 1) {
- ansL = i - rad[i] - z + 1;
- ansR = i + rad[i];
- }
- }
- }
- for (int i = ansL; i < ansR; i++)
- printf("%c", s[i]);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment