QOJ.ac

QOJ

حد الوقت: 1 s حد الذاكرة: 128 MB مجموع النقاط: 100

#16015. 重复

الإحصائيات

如果一个字符串 $s$ 是由某个长度为 $l \ge 1$ 的种子字符串 $t$ 重复拼接 $k \ge 1$ 次得到的,则称 $s$ 为一个 $(k,l)$-重复。例如,字符串 $s = \text{abaabaabaaba}$ 是一个 $(4,3)$-重复,其种子字符串为 $t = \text{aba}$。也就是说,种子字符串 $t$ 的长度为 $3$,而整个字符串 $s$ 是通过将 $t$ 重复 $4$ 次得到的。

编写一个程序完成以下任务:输入一个由字符 'a' 和/或 'b' 组成的长字符串 $u$。你的程序必须在 $u$ 中找到一个作为子串出现的 $(k,l)$-重复,并使得 $k$ 尽可能大。例如,输入字符串 $u = \text{babbabaabaabaabab}$ 包含一个从位置 5 开始的 $(4,3)$-重复 $s$(即 abaabaabaaba)。由于 $u$ 中不包含其他重复次数大于 4 的连续子串,因此你的程序必须输出这个子串的相关信息。

输入格式

输入的第一行包含一个整数 $n$ ($1 \le n \le 50000$),表示输入字符串的长度。

接下来的 $n$ 行按顺序每行包含一个字符('a' 或 'b'),代表该字符串。

输出格式

输出应包含三个整数,每行一个,按以下顺序报告你找到的 $(k, l)$-重复:

  1. 第一行包含被最大化的重复次数 $k$。
  2. 第二行包含重复了 $k$ 次的种子字符串的长度 $l$。
  3. 第三行也是最后一行包含该 $(k, l)$-重复开始的位置 $p$ ($1 \le p \le n$)。

如果对于给定的测试数据存在多个具有相同最大 $k$ 的不同解,你的程序只需报告其中任意一个即可。

样例

输入样例 1

17
b
a
b
b
a
b
a
a
b
a
a
b
a
a
b
a
b

输出样例 1

4
3
5

说明 1

在输入字符串的第 5 个字符(即输入文件的第 6 行)处找到了一个 $(4, 3)$-重复。

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.