CF1307C.Cow and Message

普及/提高-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Bessie the cow has just intercepted a text that Farmer John sent to Burger Queen! However, Bessie is sure that there is a secret message hidden inside.

The text is a string ss of lowercase Latin letters. She considers a string tt as hidden in string ss if tt exists as a subsequence of ss whose indices form an arithmetic progression. For example, the string aab is hidden in string aaabb because it occurs at indices 11, 33, and 55, which form an arithmetic progression with a common difference of 22. Bessie thinks that any hidden string that occurs the most times is the secret message. Two occurrences of a subsequence of SS are distinct if the sets of indices are different. Help her find the number of occurrences of the secret message!

For example, in the string aaabb, a is hidden 33 times, b is hidden 22 times, ab is hidden 66 times, aa is hidden 33 times, bb is hidden 11 time, aab is hidden 22 times, aaa is hidden 11 time, abb is hidden 11 time, aaab is hidden 11 time, aabb is hidden 11 time, and aaabb is hidden 11 time. The number of occurrences of the secret message is 66.

奶牛贝茜刚刚截获了农夫约翰发给汉堡王的一条消息!然而,贝茜确信其中隐藏着一条秘密信息。

该消息是一个由小写拉丁字母组成的字符串 ss。她将字符串 tt 称为在字符串 ss 中“隐藏”的,当且仅当 tt 作为 ss 的一个子序列出现,且其在 ss 中的下标构成一个等差数列。例如,字符串 aab 在字符串 aaabb 中是隐藏的,因为它出现在下标 11、33 和 55 处,这些下标构成公差为 22 的等差数列。贝茜认为,所有隐藏字符串中出现次数最多的那个即为秘密信息。若两个子序列在 ss 中所占据的下标集合不同,则视为两个不同的出现。请帮她求出该秘密信息的出现次数!

例如,在字符串 aaabb 中:

  • a 隐藏出现了 33 次,
  • b 隐藏出现了 22 次,
  • ab 隐藏出现了 66 次,
  • aa 隐藏出现了 33 次,
  • bb 隐藏出现了 11 次,
  • aab 隐藏出现了 22 次,
  • aaa 隐藏出现了 11 次,
  • abb 隐藏出现了 11 次,
  • aaab 隐藏出现了 11 次,
  • aabb 隐藏出现了 11 次,
  • aaabb 隐藏出现了 11 次。
    因此,秘密信息的出现次数为 66。

输入格式

The first line contains a string ss of lowercase Latin letters (1≤∣s∣≤1051 \le |s| \le 10^5) — the text that Bessie intercepted.

第一行包含一个由小写拉丁字母组成的字符串 ss(1≤∣s∣≤1051 \le |s| \le 10^5)——这是贝茜截获的文本。

输出格式

Output a single integer — the number of occurrences of the secret message.

输出一个整数——秘密消息出现的次数。

输入输出样例

  • 输入#1

    aaabb

    输出#1

    6
  • 输入#2

    usaco

    输出#2

    1
  • 输入#3

    lol

    输出#3

    2

说明/提示

In the first example, these are all the hidden strings and their indice sets:

  • a occurs at (1)(1), (2)(2), (3)(3)
  • b occurs at (4)(4), (5)(5)
  • ab occurs at (1,4)(1,4), (1,5)(1,5), (2,4)(2,4), (2,5)(2,5), (3,4)(3,4), (3,5)(3,5)
  • aa occurs at (1,2)(1,2), (1,3)(1,3), (2,3)(2,3)
  • bb occurs at (4,5)(4,5)
  • aab occurs at (1,3,5)(1,3,5), (2,3,4)(2,3,4)
  • aaa occurs at (1,2,3)(1,2,3)
  • abb occurs at (3,4,5)(3,4,5)
  • aaab occurs at (1,2,3,4)(1,2,3,4)
  • aabb occurs at (2,3,4,5)(2,3,4,5)
  • aaabb occurs at (1,2,3,4,5)(1,2,3,4,5)

Note that all the sets of indices are arithmetic progressions.

In the second example, no hidden string occurs more than once.

In the third example, the hidden string is the letter l.

在第一个例子中,以下是所有隐藏字符串及其对应的索引集合:

  • a 出现在 (1)(1)、(2)(2)、(3)(3) 处
  • b 出现在 (4)(4)、(5)(5) 处
  • ab 出现在 (1,4)(1,4)、(1,5)(1,5)、(2,4)(2,4)、(2,5)(2,5)、(3,4)(3,4)、(3,5)(3,5) 处
  • aa 出现在 (1,2)(1,2)、(1,3)(1,3)、(2,3)(2,3) 处
  • bb 出现在 (4,5)(4,5) 处
  • aab 出现在 (1,3,5)(1,3,5)、(2,3,4)(2,3,4) 处
  • aaa 出现在 (1,2,3)(1,2,3) 处
  • abb 出现在 (3,4,5)(3,4,5) 处
  • aaab 出现在 (1,2,3,4)(1,2,3,4) 处
  • aabb 出现在 (2,3,4,5)(2,3,4,5) 处
  • aaabb 出现在 (1,2,3,4,5)(1,2,3,4,5) 处

注意:所有索引集合均为等差数列。

在第二个例子中,没有任何隐藏字符串出现超过一次。

在第三个例子中,隐藏字符串是字母 l。

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

首页