CF1817F.Entangled Substrings

NOI/NOI+/CTSC

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Quantum entanglement is when two particles link together in a certain way no matter how far apart they are in space.

You are given a string ss. A pair of its non-empty substrings (a,b)(a, b) is called entangled if there is a (possibly empty) link string cc such that:

  • Every occurrence of aa in ss is immediately followed by cbcb;
  • Every occurrence of bb in ss is immediately preceded by acac.

In other words, aa and bb occur in ss only as substrings of acbacb. Compute the total number of entangled pairs of substrings of ss.

A string aa is a substring of a string bb if aa can be obtained from bb by the deletion of several (possibly zero or all) characters from the beginning and several (possibly zero or all) characters from the end.

量子纠缠是指两个粒子以某种方式相互关联,无论它们在空间中相距多远。

给定一个字符串 ss。其一对非空子串 (a,b)(a, b) 被称为纠缠的(entangled),当且仅当存在一个(可能为空的)连接字符串 cc,使得:

  • ss 中 aa 的每一次出现都紧随其后为 cbcb;
  • ss 中 bb 的每一次出现都紧邻其前为 acac。

换言之,aa 和 bb 在 ss 中仅作为 acbacb 的子串出现。请计算 ss 的纠缠子串对的总数。

若字符串 aa 可通过从字符串 bb 的开头删除若干(可能为零或全部)字符、并从结尾删除若干(可能为零或全部)字符而得到,则称 aa 是 bb 的子串。

输入格式

The first and only line contains a string ss of lowercase English letters (1≤∣s∣≤1051 \leq |s| \leq 10^5) — the string for which you should count pairs of entangled substrings.

第一行且唯一一行包含一个由小写英文字母组成的字符串 ss(1≤∣s∣≤1051 \leq |s| \leq 10^5),你需要统计该字符串中“纠缠子串”对的数量。

输出格式

Output a single integer, the number of entangled pairs of substrings of ss.

输出一个整数,表示字符串 ss 中纠缠子串对的数量。

输入输出样例

  • 输入#1

    abba

    输出#1

    1
  • 输入#2

    abacaba

    输出#2

    0
  • 输入#3

    abcabcabcabc

    输出#3

    5
  • 输入#4

    adamant

    输出#4

    82

说明/提示

In the first example, the only entangled pair is (ab,ba). For this pair, the corresponding link string cc is empty, as they only occur as substrings of the whole string abba, which doesn't have any characters between ab and ba.

In the second example, there are no entangled pairs.

In the third example, the entangled pairs are (a,b), (b,c), (a,c), (a,bc), and (ab,c). For most pairs, the corresponding link string cc is empty, except for the pair (a,c), for which the link string cc is b, as a and c only occur as substrings of the string abc.

在第一个例子中,唯一的纠缠对是 (ab, ba)。对于该对,对应的连接字符串 cc 为空,因为 ab 和 ba 仅作为整个字符串 abba 的子串出现,而 ab 与 ba 之间没有字符。

在第二个例子中,不存在纠缠对。

在第三个例子中,纠缠对为 (a, b)、(b, c)、(a, c)、(a, bc) 和 (ab, c)。对于大多数对,对应的连接字符串 cc 为空;但对 (a, c),其连接字符串 cc 为 b,因为 a 和 c 仅作为字符串 abc 的子串出现。

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

首页