首页 > 题解 > bzoj 1524 [POI2006]Pal

bzoj 1524 [POI2006]Pal

Description

给出n个回文串s1, s2, …, sn 求如下二元组(i, j)的个数 si + sj 仍然是回文串 规模 输入串总长不超过2M bytes

Input

The first line of input file contains the number of strings n. The following n lines describe each string: The i+1-th line contains the length of the i-th string li, then a single space and a string of li small letters of English alphabet. You can assume that the total length of all strings will not exceed 2,000,000. Two strings in different line may be the same.

Output

Print out only one integer, the number of palindromes

Sample Input

6

2 aa

3 aba

3 aaa

6 abaaba

5 aaaaa

4 abba

Sample Output

14

题解

两个串能接起来回文,那么肯定较短的那个串是较长串的一个循环节,也就是它的一个前缀。

那么对于每个串的所有前缀的串试着拼下就可以了。

具体的话搞个Trie树,然后hash一下就吼了啊


1 COMMENT

如果你觉的这篇文章不错,分享给朋友吧!

打开微信“扫一扫”,打开网页后点击屏幕右上角分享按钮

×