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

Обсуждение задачи 1684. Последнее слово Джека

How I can solve it without hash?
Послано vgu 1 мар 2009 00:08
I solve this task during contest with greedy+hash. My solution take O(n) time, but i'm interest how i can solve this without hash?
Re: How I can solve it without hash?
Послано Alex Tolstov 1 мар 2009 00:30
use z-algorithm
Re: How I can solve it without hash?
Послано Mikhail Lopatkin [NNSTU1] 1 мар 2009 01:04
You can use prefix function from KMP algorithm.
Re: How I can solve it without hash?
Послано Lomir 1 мар 2009 02:30
Simple KMP on suffixes will TLE on good tests, cause u will need to run it n times.
This problem has very weak tests.

My first idea was to use naive suffix finding algorithm for short suffix and only if there is no short (with length about 500) common suffixes then run KMP and find long one.
However I managed to get AC only with naive suffix finding algo.
Re: How I can solve it without hash?
Послано Sandro (USU) 1 мар 2009 16:08
Why n times? Jury solution calculates prefix-function only one time.
Re: How I can solve it without hash?
Послано SkorKNURE 8 мар 2009 21:52
Can you explain your solution via KMP prefix func? Thanks!
Re: How I can solve it without hash?
Послано тупой лосось 14 мар 2009 16:48
+1
i wrote it, but have tl..
Re: How I can solve it without hash?
Послано NotImplemented 17 мар 2009 20:53
I solved it using z-algorithm.

Edited by author 23.03.2009 17:26
Re: How I can solve it without hash?
Послано DK [Samara SAU 1: X2008] 19 апр 2009 19:46
How to solve it with one kmp:
a) find kmp(s1+"#"+s2)
b) if there is 0 kmp-value at any position in s2, "Yes"
c) use the fact that you can stop every prefix at any time, i.e. abrab, b is 'bad' letter, so you can output abr and continue with prefix ab