QOJ.ac

QOJ

Límite de tiempo: 1 s Límite de memoria: 1024 MB Puntuación total: 100

#2704. 字典序讲座

Estadísticas

Unsorted strings by bethrosengard on Pixabay

OUG(“德国有序大学”)是一所著名的德国大学。由于学生众多,学生 ID 都是长度相等的长字符串,且每个学生 ID 仅包含小写英文字母。不幸的是,大学校长讨厌混乱,要求学生在进入阶梯教室时必须始终按照学生 ID 的字典序升序排列。正如你所想象的那样,学生们在阶梯教室前进行排序的过程非常耗时。计算机科学专业的学生 Georgina 有一个加速这一过程的想法:她计划确定两个整数 $i$ 和 $j$(满足 $1 \le i \le j \le \ell$),表示学生 ID 中从第 $i$ 个字母开始到第 $j$ 个字母结束的子串。然后,学生们根据学生 ID 的这一子串进行字典序排序。当然,选择 $i$ 和 $j$ 时必须保证这种新的排序方式与根据完整学生 ID 进行的字典序排序结果相同。为了使过程尽可能快,子串的长度应该尽可能短。你能帮助 Georgina 解决这个问题吗?

输入格式

输入包含:

  • 一行,包含两个整数 $n$ 和 $\ell$,其中:
    • $n$ ($2 \le n \le 500$) 是学生 ID 的数量;
    • $\ell$ ($1 \le \ell \le 2 \cdot 10^4$) 是每个学生 ID 的长度。
  • $n$ 行,第 $i$ 行包含第 $i$ 个学生的学生 ID。

所有学生 ID 仅包含小写英文字母,它们两两不同,并且按字典序升序排列。

输出格式

输出两个整数,表示最短子串的起始位置和结束位置,使得学生根据该子串进行字典序排序时,其排序结果与根据完整学生 ID 进行字典序排序的结果相同。

如果存在多个最短子串,你可以输出其中任意一个。

样例

输入格式 1

4 6
aaaaaa
aaabbb
aaacaa
aaacac

输出格式 1

4 6

输入格式 2

3 5
cccca
ccgda
ccgia

输出格式 2

4 4

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.