QOJ.ac

QOJ

时间限制: 1 s 内存限制: 256 MB 总分: 100 可 Hack ✓

#6364. 最昂贵的礼物

统计

Zenyk 想要为 Marichka 准备世界上最好的礼物。他正在逛一家礼品店,想要买最昂贵的那一份。

但这并不是一家普通的商店,他们只有由字母 ‘a’、‘b’ 和 ‘c’ 组成的字符串 $S$。Zenyk 可以选择 $S$ 的任意子序列作为礼物。子序列 $T$ 是指通过删除 $S$ 中的某些(可能为零)字符,且不改变剩余字符顺序而得到的字符串。子序列 $T$ 的价格等于 $\frac{len_T^2}{c_T}$,其中 $len_T$ 是子序列 $T$ 的长度,$c_T$ 是 $T$ 的最小循环节长度。

字符串 $R$ 是字符串 $T$ 的循环节,如果: $length(R)$ 是 $length(T)$ 的约数。 对于所有 $i \in [0, length(T) - 1]$(下标从 0 开始),满足 $R_{i \pmod{length(R)}} = T_i$。

请帮助 Zenyk 找到最昂贵礼物的价格。

输入格式

第一行包含一个整数 $N$,表示字符串 $S$ 的长度 ($1 \le N \le 10^4$)。 第二行包含由字母 ‘a’、‘b’ 和 ‘c’ 组成的字符串 $S$。

输出格式

输出一个整数,表示最昂贵礼物的价格。

样例

输入格式 1

11
abcabacbcac

输出格式 1

18

说明

其中一个最昂贵的子序列是 “ababab”。它的长度为 6,最小循环节长度为 2。因此该子序列的价格等于 $\frac{6^2}{2} = 18$。还有其他价格相同的子序列。

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.