ENG  RUSTimus Online Judge
Online Judge
Задачи
Авторы
Соревнования
О системе
Часто задаваемые вопросы
Новости сайта
Форум
Ссылки
Архив задач
Отправить на проверку
Состояние проверки
Руководство
Регистрация
Исправить данные
Рейтинг авторов
Текущее соревнование
Расписание
Прошедшие соревнования
Правила
вернуться в форум

Обсуждение задачи 1354. Палиндром. Он же палиндром

Показать все сообщения Спрятать все сообщения

how did use KMP algo to structure palindrom? lian lian 26 авг 2008 05:17

I think the question for some day, but I can`t solve....

please give hint.....

Edited by author 26.08.2008 05:22
First you can calculate prefix array for reversed word. And then run algorithm that finds occurence or reversed word in S1, but stop it when forward and backard iterators meet each other. Ignore requirement S2 to be nonempty for now, and take it into account when algorithm will be almost ready
Re: how did use KMP algo to structure palindrom? Artem Khizha [DNU] 19 июл 2011 16:27
Consider A - original string, B - reversed.
Build preffix array for B, run KMP (search for B in A) with slight fix. In usual KMP you find a number of letters, that coincide in strings, and want it to be equal to size of B. In this problem you just remember this number (let it be Q). So after KMP you know, that last Q letters are a palindrome.

The only moment is what needs to be done, if Q == size of A. Then you should undo last KMP step (Q = P[Q-1]) and find previous palindrome.