CF159D.Palindrome pairs

普及/提高-

通过率:0%

时间限制:3.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

You are given a non-empty string s consisting of lowercase letters. Find the number of pairs of non-overlapping palindromic substrings of this string.

In a more formal way, you have to find the quantity of tuples (a, b, x, y) such that 1 ≤ a ≤ b < x ≤ y ≤ |s| and substrings s[a... b], s[x... y] are palindromes.

A palindrome is a string that can be read the same way from left to right and from right to left. For example, "abacaba", "z", "abba" are palindromes.

A substring s[i... j] (1 ≤ i ≤ j ≤ |s|) of string s = _s_1_s_2... s|s| is a string s__i__s__i + 1... s__j. For example, substring s[2...4] of string s = "abacaba" equals "bac".

给你一个非空字符串 ss,它仅由小写字母组成。请找出该字符串中所有不重叠的回文子串对的数量。

更形式化地说,你需要计算满足以下条件的四元组 (a, b, x, y)(a,\,b,\,x,\,y) 的数量:

1 ≤ a ≤ b < x ≤ y ≤ ∣s∣1 \le a \le b < x \le y \le |s|

且子串 s[a…b]s[a\ldots b] 与 s[x…y]s[x\ldots y] 均为回文串。

回文串是指从左到右读和从右到左读完全相同的字符串。例如,“abacaba”、“z”、“abba” 都是回文串。

字符串 s=s1s2…s∣s∣s = s_1s_2\ldots s_{|s|} 的子串 s[i…j]s[i\ldots j](其中 1 ≤ i ≤ j ≤ ∣s∣1 \le i \le j \le |s|)定义为字符串 sisi+1…sjs_is_{i+1}\ldots s_j。例如,当 s=s = “abacaba” 时,其子串 s[2…4]s[2\ldots 4] 等于 “bac”。

输入格式

The first line of input contains a non-empty string s which consists of lowercase letters ('a'...'z'), s contains at most 2000 characters.

输入的第一行包含一个非空字符串 ss,该字符串由小写字母('a'...'z')组成,且 ss 的长度最多为 2000 个字符。

输出格式

Output a single number — the quantity of pairs of non-overlapping palindromic substrings of s.

Please do not use the %lld format specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d format specifier.

输出一个整数——字符串 ss 中互不重叠的回文子串对的数量。

在 C++ 中,请勿使用 %lld 格式说明符读取或写入 64 位整数。推荐使用 cin、cout 流,或 %I64d 格式说明符。

输入输出样例

  • 输入#1

    aa

    输出#1

    1
  • 输入#2

    aaa

    输出#2

    5
  • 输入#3

    abacaba

    输出#3

    36

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

首页