問題一覧 > 通常問題

No.263 Common Palindromes Extra

レベル : / AI推定難易度 : 2300 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 192 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 46
作問者 : uwi / テスター : anta
お気に入りにしたユーザー ProblemId : 399 / 自分の提出
問題文最終更新日: 2026-06-30 21:28:55
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
yukicoder 1周年記念 復習コンテスト R2 (順位表) の他の問題:

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もしくは右上の雲マークをクリックしてアカウントを作成してください。