問題一覧 > 通常問題

No.2606 Mirror Relay

レベル : / AI推定難易度 : 2100 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (解説公開後に AC するまで非表示) / 解いたユーザー数 34
作問者 : 👑 amentorimaru / テスター : 👑 seekworser
お気に入りにしたユーザー ProblemId : 10280 / 自分の提出
問題文最終更新日: 2024-01-13 09:25:59
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 contest 414 (順位表) の他の問題:

Problem Statement

In a certain virtual space, people spend their time in a first-person view, but in front of a mirror they can check what they look like, so mirrors have become a hangout spot for many people.

Inspired by such mirrors, Etowanyu proposed a game: a relay of finding many palindromes.


You are given a string $S$ of lowercase English letters.

In addition, you are given an empty string $X$, and you may repeat the following operation as many times as you like. Initially, the score is $0$.

  • Append any one lowercase English letter of your choice to the end of $X$, and the score is calculated as follows.
    • If $X$ is not a palindrome, the score does not change.
    • If $X$ is a palindrome, let $Y$ be the number of occurrences of $X$ in $S$; then $|X|\times Y$ points are added.

Find the maximum score obtainable in this relay.


Note that the occurrences of $X$ in $S$ are counted with overlapping intervals allowed.

Strictly speaking, this is defined as the number of $i$ among $i=1,2,\dots ,|S|-|X|+1$ such that the substring of $S$ from the $i$-th character to the $i+|X|-1$-th character is equal to $X$.

Input

$S$

  • $S$ is a string of lowercase English letters.
  • $1\le |S| \le 2\times 10^5$

Output

Output the answer.

Sample

Sample 1
Input
baabaabaacaa
Output
34

Appending to the end in the order aabaabaa from the start gives $1\times 8 + 2\times 4 + 0+0+5\times 2 + 0+0+8\times 1=34$, which is the highest score.

For example, when aa is formed, $|X|=2$ and $Y=4 (i=2,5,8,11)$, so $2 \times 4 = 8$ is added.

Also, when aabaa is formed, $|X|=5$ and $Y=2(i=2,5)$, so $5 \times 2 = 10$ is added. These two occurrences overlap at the middle aa, but they may be counted with the overlap.

aabaab is not a palindrome, so no points are added.


As another option, appending to the end in the order baabaab gives $1\times 3+0+0+4\times 2+0+0+7\times 1 = 18$, but this is not the highest score.

Sample 2
Input
abc
Output
1

Sample 3
Input
zzzzabcddcba
Output
20

Sample 4
Input
disablepixellightsmirrorresolutionturnoffmirrorocclusionreflectlayersmaximumantialiasing
Output
21

提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。