CF1789F.Serval and Brain Power

省选/NOI-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Serval loves Brain Power and his brain power problem.

Serval defines that a string TT is powerful iff TT can be obtained by concatenating some string T′T' multiple times. Formally speaking, TT is powerful iff there exist a string T′T' and an integer k≥2k\geq 2 such that $$T=\underbrace{T'+T'+\dots+T'}_{k\text{ times}}$$

For example, gogogo is powerful because it can be obtained by concatenating go three times, but power is not powerful.

Serval has a string SS consists of lowercase English letters. He is curious about the longest powerful subsequence of SS, and he only needs you to find out the length of it. If all the non-empty subsequences of SS is not powerful, the answer is considered to be 00.

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

Serval 热爱“脑力值”(Brain Power),并且热衷于解决与之相关的题目。

Serval 定义:一个字符串 TT 是强字符串(powerful),当且仅当 TT 可以通过将某个字符串 T′T' 重复拼接若干次得到。形式化地说,TT 是强字符串当且仅当存在某个字符串 T′T' 和某个整数 k≥2k\geq 2,使得

T=T′+T′+⋯+T′⏟k timesT=\underbrace{T'+T'+\dots+T'}_{k\text{ times}}

例如,gogogo 是强字符串,因为它可以由 go 重复拼接三次得到;但 power 不是强字符串。

Serval 有一个仅由小写英文字母组成的字符串 SS。他很好奇:SS 的最长强子序列的长度是多少?你只需输出该长度。若 SS 的所有非空子序列均不是强字符串,则答案为 00。

字符串 aa 是字符串 bb 的子序列(subsequence),当且仅当 aa 可通过从 bb 中删除若干个(可能为零个或全部)字符而得到。

输入格式

The first line contains a single string SS (∣S∣≤80|S|\leq 80) consisting of lowercase English letters.

第一行包含一个仅由小写英文字母组成的字符串 SS(∣S∣≤80|S|\leq 80)。

输出格式

Print a single integer — the length of the longest powerful subsequence of SS. If all the non-empty subsequences of SS is not powerful, print 00.

输出一个整数——字符串 SS 的最长强子序列的长度。如果 SS 的所有非空子序列均不为强子序列,则输出 00。

输入输出样例

  • 输入#1

    buaa

    输出#1

    2
  • 输入#2

    codeforcesround

    输出#2

    6
  • 输入#3

    oooooooooooaaaaeaaiaujooooooooooooo

    输出#3

    24
  • 输入#4

    zero

    输出#4

    0

说明/提示

For the first sample, all of the non-empty subsequences of buaa are listed below:

  • b
  • u
  • a (occurred twice, buaa and buaa)
  • bu
  • ba (occurred twice, buaa and buaa)
  • ua (occurred twice, buaa and buaa)
  • aa
  • bua (occurred twice, buaa and buaa )
  • baa
  • uaa
  • buaa

Since aa=a+a\texttt{aa} = \texttt{a} + \texttt{a}, aa is a powerful subsequence. It can be shown that aa is the only powerful subsequence among them. So the answer is 22.

For the second sample, the longest powerful subsequence is codcod from codeforcesround. So the answer is 66.

对于第一个样例,字符串 buaa 的所有非空子序列如下所示:

  • b
  • u
  • a(出现两次,分别来自 buaa 和 buaa)
  • bu
  • ba(出现两次,分别来自 buaa 和 buaa)
  • ua(出现两次,分别来自 buaa 和 buaa)
  • aa
  • bua(出现两次,分别来自 buaa 和 buaa)
  • baa
  • uaa
  • buaa

由于 aa=a+a\texttt{aa} = \texttt{a} + \texttt{a},因此 aa 是一个强子序列。可以验证,aa 是其中唯一的强子序列。故答案为 22。

对于第二个样例,最长的强子序列是 codeforcesround 中的 codcod。因此答案为 66。

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

首页