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 | 3496 |

2 | moejy0viiiiiv | 3288 |

3 | W4yneb0t | 3218 |

4 | TakanashiRikka | 3178 |

5 | Petr | 3173 |

6 | dotorya | 3117 |

7 | izrak | 3109 |

7 | Um_nik | 3109 |

9 | anta | 3106 |

10 | ershov.stanislav | 3105 |

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

1 | rng_58 | 174 |

2 | csacademy | 169 |

3 | Swistakk | 160 |

4 | tourist | 157 |

4 | Petr | 157 |

6 | Errichto | 154 |

7 | Zlobober | 147 |

8 | matthew99 | 142 |

9 | Endagorion | 141 |

10 | BledDest | 134 |

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-2017 Mike Mirzayanov

The only programming contests Web 2.0 platform

Server time: Nov/21/2017 03:54:36 (c4).

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.