No.2606 Mirror Relay
タグ : / 解いたユーザー数 34
作問者 : 👑
amentorimaru
/ テスター :
👑 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もしくは右上の雲マークをクリックしてアカウントを作成してください。