Hello!

Guys, I'd like to know how to find the largest common pallindrom of N (1 <= N <= 15) strings. I know the Manachers algorithm finds in linear time for a string. How would I find the common N-strings?

Thank you: D

# | User | Rating |
---|---|---|

1 | tourist | 3434 |

2 | fateice | 3337 |

3 | Um_nik | 3292 |

4 | OO0OOO00O0OOO0O0…O | 3280 |

5 | Syloviaely | 3274 |

6 | Petr | 3223 |

7 | Swistakk | 3105 |

8 | mnbvmar | 3096 |

9 | yosupo | 3091 |

10 | dotorya | 3081 |

# | User | Contrib. |
---|---|---|

1 | rng_58 | 164 |

2 | tourist | 161 |

3 | csacademy | 152 |

4 | Petr | 150 |

5 | Swistakk | 148 |

6 | Um_nik | 144 |

7 | Nickolas | 142 |

7 | Vovuh | 142 |

9 | BledDest | 138 |

9 | PikMike | 138 |

9 | matthew99 | 138 |

9 | Errichto | 138 |

Hello!

Guys, I'd like to know how to find the largest common pallindrom of N (1 <= N <= 15) strings. I know the Manachers algorithm finds in linear time for a string. How would I find the common N-strings?

Thank you: D

↑

↓

Codeforces (c) Copyright 2010-2018 Mike Mirzayanov

The only programming contests Web 2.0 platform

Server time: Jul/21/2018 18:37:04 (d2).

Desktop version, switch to mobile version.

User lists

Name |
---|

You could probably pre-compute some numbers like "what's the longest palindrome that is centered around position i" for every string and use suffix array with LCP + binary search on the length using a two-pointer algorithm to find the answer.

I'm not that sure since I've never used suffix array for anything nor do I know how Manacher's algorithm works.

Palindromic tree will work:

As the number of strings

N≤ 15, for every vertex in the tree we can save a mask of all strings in which the corresponding substring appears. This can be done by simply building the palindromic tree for all strings and then for every preffix vertex (the last vertex before adding a letter) we change its mask (we add the current strings index to the mask). Then after the building we iterate all vertices, starting from the longest one, and we add the current vertex's mask to its link's mask. After that, the strings we are interested in are the ones with mask equal to 2^{N}- 1 (if we use 0-indexing for the strings).PS:There is a way to do this forN≤ 10^{6}by building virtual trees. If anyone is interested I can explain.Could you explain?

You build another tree (the vertices are kept the same but the edges are changed), such that there is an edge between

uandlink_{u}for everyu. This will help us, because now every node contained as a suffix in this node, is on the path from the root of our tree to this vertex.Now for every of the

Nstrings we mark every preffix vertex/node. All palindromic substrings occuring in the current tree are those which have a marked vertex in their subtree. We will add for all these vertices +1. This can be done by building a compressed tree of the marked vertices (virtual tree).After this the strings/nodes which we are interested in are the ones with value equal to

N.The complexity will be , where

Sis the sum of lengths of the trees.You can solve it with suffix arrays. You can binary search the length of the largest common palindrome: Consider you are verifying for length X. Go to the first string and find a palindrome of length X(you can do this in a lot of ways) and then check whether that substring appears in all the others with your suffix array. Considering you have L=max length of a string, the time complexity would be O(N*L*logL + logL*L*N*logL) or something similar(N*L*logL for suffix array and logL(binary search)*L(finding palindrome)*N(going through the other words)*logL(finding whether the palindrome I found in the first string appears in my current substring by binary searching on the list of sorted suffixes)).

Good day to you,

Firstly — if I'm not mistaken, the statement (might?) be similar to this. As long as it is true, I've just mentioned an approach here (even though I admit I write bad hints), which solves the problem using Binary Search + Hashing. If I'm not mistaken, it is slightly similar to arif.ozturk solution (even though it uses different machinery).

Complexity of the solution is

O(n|s|log(|s|)^{2}) (orO(n|s|log(|s|)) with proper sort :) )Good Luck & Wish you a nice day!

You need the table on the page 8 in my paper.

There are online algorithm in O(n log sigma) and offline algorithm in O(n), where n — is the sum of lengths of all strings.