First non-PalindromeProblem code: NONPALIN |
All submissions for this problem are available.
For the given string S of length N you need to find for each L from 1 to N the first non-palindrome substring of S that has length L. That is, for each L from 1 to N you need to find the smallest positive integer K <= N - L + 1 such that the string S[K, K + L - 1] is not a palindrome. Denote this number by K(L). Here S[i, j] stands for the substring of S composed of its characters in positions i, i + 1, ..., j. Characters of S are numbered from 1 to N. If for some L there is no such K set K(L) = 0. After you find all numbers K(1), K(2), ..., K(N) output the following sum
modulo 264.
Remark. The string is called a palindrome if it coincides with its reverse. So abacaba and abba are palindromes but codechef and abbc are not.
Input
The first line contains a single integer T, the number of test cases. T test cases follow. The only line of each test case contains a non-empty string composed only of lowercase letters of the English alphabet.
Output
For each test case, output a single line containing the corresponding sum constructed by numbers K(1), K(2), ..., K(N) as mentioned in the problem statement modulo 264.
Constraints
1 <= T <= 20
1 <= length of S <= 100000
Example
Input: 4 abacaba abba codechef aaaa Output: 12789123637940213592 10001500056 18134494634143926857 0
Explanation
Actual values of K(1), K(2), ..., K(N) in the tests are:abacaba: {0, 1, 2, 1, 1, 1, 0}
abba: {0, 1, 1, 0}
codechef: {0, 1, 1, 1, 1, 1, 1, 1}
aaaa: {0, 0, 0, 0}
| Date: | 2011-10-14 |
| Time limit: | 6s |
| Source limit: | 50000B |
| Languages: | All |
Comments
Loading Comments...
SUCCESSFUL SUBMISSIONS FOR THIS PROBLEM:
Loading Submissions...RECENT ACTIVITY FOR THIS PROBLEM:
Loading Recent Activity...HELP
Program should read from standard input and write to standard output.
After you submit a solution you can see your results by clicking on the [My Submissions] tab on the problem page. Below are the possible results:
- Accepted
Your program ran successfully and gave a correct answer. If there is a score for the problem, this will be displayed in parenthesis next to the checkmark. - Time Limit Exceeded
Your program was compiled successfully, but it didn't stop before time limit. Try optimizing your approach. - Wrong Answer
Your program compiled and ran succesfully but the output did not match the expected output. - Runtime Error
Your code compiled and ran but encountered an error. The most common reasons are using too much memory or dividing by zero. For the specific error codes see the help section. - Compilation Error
Your code was unable to compile. When you see this icon, click on it for more information.
If you are still having problems, see a sample solution here.
