F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

Harry and magic string

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 953    Accepted Submission(s): 470


Problem Description
Harry got a string T, he wanted to know the number of T¡¯s disjoint palindrome substring pairs. A string is considered to be palindrome if and only if it reads the same backward or forward. For two substrings of $T: \, x = T[a_1 \ldots b_1], \, y = T[a_2 \ldots b_2]$(where a1 is the beginning index of $x, b_1$ is the ending index of x. $a_2, b_2$ as the same of y), if both x and y are palindromes and $b_1 < a_2 \text{ or } b_2 < a_1$ then we consider (x, y) to be a disjoint palindrome substring pair of T.
 

Input
There are several cases.
For each test case, there is a string T in the first line, which is composed by lowercase characters. The length of T is in the range of [1,100000].
 

Output
For each test case, output one number in a line, indecates the answer.
 

Sample Input
aca aaaa
 

Sample Output
3 15
 

Hint
For the first test case there are 4 palindrome substrings of T.
They are:
S1=T[0,0]
S2=T[0,2]
S3=T[1,1]
S4=T[2,2]
And there are 3 disjoint palindrome substring pairs.
They are:
(S1,S3) (S1,S4) (S3,S4).
So the answer is 3.
 

Source
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2024 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.000000(s) query 1, Server time : 2024-04-26 08:51:23, Gzip enabled