QOJ.ac

QOJ

Límite de tiempo: 2 s Límite de memoria: 256 MB Puntuación total: 100

#938. 四叉树

Estadísticas

给定一个大小为 $2^m \times 2^m$ 的正方形位图。位图中的每个像素要么是白色的,要么是黑色的。这种位图可以用四叉树进行压缩表示。如果位图的所有像素都是白色的,则树由一个标签为 0 的节点组成。如果所有像素都是黑色的,则树由一个标签为 1 的节点组成。否则,树的根节点标签为 4,并拥有四个子树,分别对应位图的四个象限(大小为 $2^{m-1} \times 2^{m-1}$,顺序为左上、右上、左下、右下)。该树可以用一个由字符 0、1 和 4 组成的字符串来描述:树的描述以其根节点的标签开始,后面依次是其子树的描述。下图展示了一个 $m = 3$ 的示例位图及其对应的四叉树,其描述字符串为 404004111014001410011

我们将“区域”定义为一组最大的相邻黑色像素集合(如果两个像素共边,则它们相邻)$^*$。对于给定的描述位图的字符串,请确定区域的数量以及其中最大的区域的大小。在上面的例子中,有两个区域,大小分别为 24 和 5。

输入格式

第一行包含一个整数 $m$ ($m \ge 0$),表示位图的大小。 第二行包含一个非空的、由字符 0、1 和 4 组成的字符串,用于编码位图。你可以假设输入是正确的,特别是四叉树的高度(即从根到最深节点的路径上的边数)不超过 $m$。位图至少包含一个黑色像素。

输出格式

你的程序应输出两行。第一行应包含一个数字,表示位图中的区域数量。第二行应包含一个数字,表示最大区域的大小。由于第二个数字可能非常大,请输出其对 $10^9 + 7$ 取模后的结果。

样例

输入 1

3
404004111014001410011

输出 1

2
24

说明

$^*$ 正式地,我们将区域定义为一组黑色像素,使得从其中任何一个像素出发,都可以通过经过一定数量的黑色像素(其中每两个相邻像素共边)到达任何其他像素。如果一个区域不能再添加任何其他黑色像素而仍然保持为区域,则称其为最大区域。在本题中,我们只考虑最大区域。

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.