Блог пользователя arif.ozturk

Автор arif.ozturk, история, 7 лет назад, По-английски

Hello, I recently got an interesting question from my old teacher. Given two strings A and B(of size <=2000000) find the sum of the longest common prefixes of A and all substrings of B. I reduced this to finding the longest common prefix of A and all suffixes of B and found a solution in O(NlogN) time using suffix arrays. Because it consumed a lot of memory, I switched to hashing and it worked to some extent but it seems O(NlogN) is too large as I get TLE. I was thinking whether I could change the KMP algorithm a bit to get exactly what I need but I can't seem to find a way. Do you guys have any ideas?

  • Проголосовать: нравится
  • 0
  • Проголосовать: не нравится

»
7 лет назад, # |
Rev. 2   Проголосовать: нравится 0 Проголосовать: не нравится

You can concatenate A and B and run Z-function on it. In O(n+m) you get want you want (length of LCP for all suffix of B)