QOJ.ac

QOJ

时间限制: 12 s 内存限制: 2048 MB 总分: 100

#2432. 顺其自然

统计

在排版中,“河流”(river)是指由单词之间的间隙形成的、延伸穿过数行文本的空格串。例如,图 F.1 展示了几个以红色高亮显示的河流示例(文本经过故意模糊处理,以使河流更加明显)。

图 F.1:排版文本中的河流示例。

著名的河流权威 Flo Ng 希望她关于世界河流的新书能包含尽可能长的排版河流。她计划使用等宽字体(所有字母和空格宽度相同)将文本排版在固定宽度的左对齐列中,每行单词之间恰好有一个空格(文本右侧不对齐)。对于 Flo 而言,“河流”定义为连续行中空格的一个序列,其中序列中每个空格的位置(第一个除外)与上一行中空格的位置之差不超过 1。行尾的空白不能出现在河流中。单词必须尽可能紧凑地排列在行中;单词不能跨行拆分。所使用的行宽必须至少与文本中最长的单词一样长。例如,图 F.2 展示了同一段文本在两种不同行宽下的排版效果。

图 F.2:两种不同行宽下的最长河流(用 * 标记)。

给定一段文本,你的任务是确定能使该文本产生最长空格河流的行宽。

输入格式

输入的第一行包含一个整数 $n$ ($2 \le n \le 2\,500$),表示文本中的单词数。接下来的几行包含文本的单词。每个单词仅由大小写字母组成,同一行上的单词由单个空格分隔。没有任何单词超过 80 个字符。

输出格式

输出能使输入文本包含最长可能河流的行宽,以及该最长河流的长度。如果多个行宽都能达到此最大长度,则输出其中最小的行宽。

样例

样例输入 1

21
The Yangtze is the third longest
river in Asia and the longest in
the world to flow
entirely in one country

样例输出 1

15 5

样例输入 2

25
When two or more rivers meet at
a confluence other than the sea
the resulting merged river takes
the name of one of those rivers

样例输出 2

21 6

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.