No.263 Common Palindromes Extra
Problem Statement
Once upon a time, there was a problem called Common Palindromes, which, as its name suggests, asked for the number of pairs of common palindromic substrings of $2$ strings. This problem caused the contestants of the time a great deal of suffering. More than $3$ years have passed since then, and both CPU performance and the quality of competitive programmers have improved dramatically. The fastest execution time for Common Palindromes is said to be under $0.05$ seconds. Therefore, it should surely still be solvable even if the string lengths are multiplied by $10$.
Given $2$ strings $S, T$, find the number of tuples $(i,j,k,l)$ satisfying all of the following conditions. Here, $U[x,y]$ denotes the contiguous substring of a string $U$ from the $x$-th character through the $y$-th character.
- $1\le i\le j\le (Sの長さ).$
- $1\le k\le l\le (Tの長さ).$
- $S[i,j]=T[k,l].$
- $S[i,j]$ is a palindrome.
Input
$S$ $T$
- $1\le (Sの長さ)\le 500000$
- $1\le (Tの長さ)\le 500000$
- $S, T$ consist only of uppercase English letters ('A'-'Z')
- From the above constraints, the answer is guaranteed to always be at most $10^{18}$.
- * The constraints of this problem are set slightly tight so that copying and pasting published code for the original problem will not get AC!!
Output
Output the number of tuples $(i,j,k,l)$. Print a newline at the end.
Sample
Sample 1
Input
AABA BAAB
Output
9
There are $9$ tuples: $(1,1,2,2),(1,1,3,3),(2,2,2,2),(2,2,3,3),(4,4,2,2),(4,4,3,3),(3,3,1,1),(3,3,4,4),(1,2,2,3)$.
Sample 2
Input
USAGI MYON
Output
0
Of course, the sample cases of the original problem also pass.
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。
anta