AT_abc468_d.Pre-Palindrome

普及-

通过率:0%

时间限制:2.00s

内存限制:1024MB

AC君温馨提醒

该题目为【atcoder】题库的题目,您提交的代码将被提交至atcoder进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

A string consisting of lowercase English letters is called a good string if it satisfies the following condition.

  • It can be turned into a palindrome by rewriting at most one character.

For example, a, iwai, and abcdcza are good strings, but abcd and atcoder are not good strings. Note that, in particular, a palindrome is also a good string.

You are given a string SS consisting of lowercase English letters.

Find the number of non-empty substrings (contiguous subsequences) of SS that are good strings.

Two substrings taken from different positions of SS are counted separately even if they are equal as strings.

What is a substring?

A substring of SS is a string obtained by deleting zero or more characters from the beginning and zero or more characters from the end of SS.
For example, ab is a substring of abc, but ac is not a substring of abc.

仅由小写英文字母组成的字符串被称为好字符串,当且仅当它满足以下条件:

  • 最多修改一个字符,即可将其变为回文串。

例如,a、iwai 和 abcdcza 是好字符串,但 abcd 和 atcoder 不是好字符串。注意,特别地,任意回文串本身也是好字符串。

给定一个仅由小写英文字母组成的字符串 SS。

请计算 SS 的非空子串(连续子序列)中,有多少个是好字符串。

即使两个子串作为字符串内容相同,只要它们在 SS 中起始或结束位置不同,就视为不同的子串,需分别计数。

什么是子串?

字符串 SS 的一个子串是指:从 SS 的开头删除零个或多个字符,再从 SS 的末尾删除零个或多个字符后所得到的字符串。
例如,ab 是 abc 的子串,但 ac 不是 abc 的子串。

输入格式

The input is given from Standard Input in the following format:

SS

输入从标准输入中以如下格式给出:

SS

输出格式

Output the answer.

输出答案。

输入输出样例

  • 输入#1

    ababa

    输出#1

    13
  • 输入#2

    atcoder

    输出#2

    18
  • 输入#3

    abccbacbacb

    输出#3

    40

说明/提示

Sample 1 Explanation:
The substring ba from the 22nd through 33rd characters of SS and the substring ababa from the 11st through 55th characters are some good strings.

Among the 1515 substrings, the good strings are the 1313 substrings other than abab from the 11st through 44th characters and baba from the 22nd through 55th characters.

Constraints

  • SS is a string of length between 11 and 10410^4, inclusive, consisting of lowercase English letters.

样例 1 解释:
字符串 SS 中第 22 至第 33 个字符构成的子串 ba,以及第 11 至第 55 个字符构成的子串 ababa 均为“好字符串”。

在全部 1515 个子串中,“好字符串”共有 1313 个,即除去以下两个子串:第 11 至第 44 个字符构成的 abab,以及第 22 至第 55 个字符构成的 baba。

约束条件

  • SS 是一个长度在 11 到 10410^4(含)之间的字符串,仅由小写英文字母组成。

输入解题思路,AI测评打分。不知道怎么写?

首页