QOJ.ac

QOJ

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

#23928. 填色

الإحصائيات

题目描述

JOI 君正在玩绘图软件。

在绘图软件中,可以在纵 $H$ 行、横 $W$ 列的长方形网格上画画。每个格子都有确定的颜色,颜色用 $1$ 以上 $10^9$ 以下的整数表示。

将从上往下第 $i$ 行($1 \le i \le H$)、从左往右第 $j$ 列($1 \le j \le W$)的格子称为格子 $(i,j)$。目前,格子 $(i,j)$ 的颜色为 $A_{i,j}$。

从格子 $(i,j)$ 出发,重复移动到有公共边的相邻格子,且不进入任何与格子 $(i,j)$ 颜色不同的格子所能到达的格子的集合,在这里称为格子 $(i,j)$ 的区域。

绘图软件有一个称为填色的功能。在该功能中,指定某个格子 $(x,y)$($1 \le x \le H$,$1 \le y \le W$)与颜色 $c$($1 \le c \le 10^9$)后,包含在格子 $(x,y)$ 的区域中的所有格子的颜色都会变为 $c$。

JOI 君选择某个格子 $(x,y)$ 与颜色 $c$,指定该格子和颜色并恰好使用 $1$ 次填色功能。使用填色功能后,包含在格子 $(x,y)$ 的区域中的格子个数即为 JOI 君的得分。

请编写程序求出 JOI 君能够达到的得分的最大值。

输入格式

输入按以下格式给出:

H W
A_{1,1} A_{1,2} \ldots A_{1,W}
A_{2,1} A_{2,2} \ldots A_{2,W}
:
A_{H,1} A_{H,2} \ldots A_{H,W}

输出格式

在 $1$ 行内输出 JOI 君能够达到的得分的最大值。

数据范围

  • $1 \le H \le 500$。
  • $1 \le W \le 500$。
  • $1 \le A_{i,j} \le 10^9$($1 \le i \le H$,$1 \le j \le W$)。
  • 输入的值均为整数。

子任务

  1. ($9$ 分)$H = 1$。
  2. ($32$ 分)$H \le 30$,$W \le 30$,$A_{i,j} \le 5$($1 \le i \le H$,$1 \le j \le W$)。
  3. ($18$ 分)$H \le 30$,$W \le 30$。
  4. ($10$ 分)$A_{i,j} \le 2$($1 \le i \le H$,$1 \le j \le W$)。
  5. ($31$ 分)无额外约束。

样例

样例输入 1

4 4
1 2 3 1
2 2 3 1
1 2 3 1
3 3 2 2

样例输出 1

9

在初始时刻,包含在格子 $(2,2)$ 的区域中的格子有格子 $(1,2), (2,1), (2,2), (3,2)$ 共 $4$ 个。因此,如果指定格子 $(2,2)$ 和颜色 $3$ 使用填色功能,如下图所示,这 $4$ 个格子的颜色会变为 $3$。

problem_23928_f670918b4b8047ebeaf9bad79de947bd.png

使用填色功能后,包含在格子 $(2,2)$ 的区域中的格子变成格子 $(1,2), (1,3), (2,1), (2,2), (2,3), (3,2), (3,3), (4,1), (4,2)$ 共 $9$ 个。因此,JOI 君的得分为 $9$。

因为无法使 JOI 君的得分达到 $10$ 或以上,所以输出 $9$。

该输入满足子任务 $2, 3, 5$ 的限制。


样例输入 2

2 10
1 2 2 1 3 3 3 3 1 1
1 1 1 1 1 1 1 3 3 3

样例输出 2

18

该输入满足子任务 $2, 3, 5$ 的限制。


样例输入 3

5 5
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1

样例输出 3

25

该输入满足子任务 $2, 3, 4, 5$ 的限制。

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.