QOJ.ac

QOJ

実行時間制限: 2.0 s メモリ制限: 256 MB 満点: 100 ハック可能 ✓

#12119. 山丘

統計

Amanbol 拥有一个大小为 $n \times m$ 的表格 $A$。表格的行编号为 $1$ 到 $n$,列编号为 $1$ 到 $m$。表格中的每个单元格要么包含字符 'X',要么包含一个 '0' 到 '9' 之间的数字。

如果表格单元格中写有字符 'X',则表示 Amanbol 将该单元格标记为阻塞。否则,写在该单元格上的数字表示其值。

在最近的一次登山旅行后,Amanbol 想要在他的表格中找到一个“山丘”(hill)。他定义山丘如下:

  1. 首先,我们选择两个数字 $(s, e)$,使得 $(1 \le s \le e \le n)$。
  2. 然后,对于每个 $k$ $(s \le k \le e)$,我们选择一个数对 $(L_k, R_k)$,使得 $(1 \le L_k \le R_k \le m)$。
  3. 必须满足条件 $L_s \ge L_{s+1} \ge \dots \ge L_e$ 以及 $R_s \le R_{s+1} \le \dots \le R_e$。

我们称一个单元格 $(x, y)$ 属于一个山丘,如果 $s \le x \le e$ 且 $L_x \le y \le R_x$。在所有可能的山丘中,Amanbol 想要找到一个不包含任何阻塞单元格且所有单元格总值最大的山丘。请帮助他完成这项任务!

输入格式

第一行包含两个整数 $n$ 和 $m$ $(1 \le n, m \le 2500)$,表示表格 $A$ 的行数和列数。

接下来的 $n$ 行中,第 $i$ 行包含恰好 $m$ 个字符 $A_{i,1}, \dots, A_{i,m}$。

保证每个表格单元格要么是字符 'X',要么是 '0' 到 '9' 之间的数字。同时保证表格中至少存在一个山丘。

输出格式

输出一个整数,表示山丘所有单元格的最大可能总值。

子任务

子任务 附加限制 分值 所需子任务
0 样例 0
1 $n = 1$ 12
2 无阻塞单元格 7
3 $n, m \le 50$ 25 0
4 $n, m \le 300$ 22 3
5 34 1, 2, 4

样例

输入格式 1

4 4
5175
312X
1XX9
20X8

输出格式 1

19

输入格式 2

1 6
1X23X4

输出格式 2

5

说明

第一个样例

在第一个样例中,例如,以下山丘是可能的:

  1. 选择 $s = 3, e = 4$。然后选择 $(L_3, R_3) = (4, 4)$ 和 $(L_4, R_4) = (4, 4)$(在第一张图中用红色标记)。该山丘单元格的总值为 $9 + 8 = 17$。
  2. 选择 $s = 1, e = 4$。然后对于所有 $k$ $(1 \le k \le 4)$ 选择 $(L_k, R_k) = (1, 1)$(在第一张图中用绿色标记)。该山丘单元格的总值为 $5 + 3 + 1 + 2 = 11$。
  3. 选择 $s = 1, e = 2$。然后选择 $(L_1, R_1) = (1, 3)$ 和 $(L_2, R_2) = (1, 3)$(在第一张图中用蓝色标记)。该山丘单元格的总值为 $19$。

而以下山丘,例如,是无效的:

  1. 选择 $s = 1, e = 2$。然后选择 $(L_1, R_1) = (1, 4)$ 和 $(L_2, R_2) = (1, 3)$(在第二张图中用绿色标记)。该山丘无效,因为条件 $R_1 \le R_2$ 未满足。
  2. 选择 $s = 4, e = 4$。然后选择 $(L_4, R_4) = (1, 4)$(在第二张图中用红色标记)。该山丘无效,因为该山丘包含一个阻塞单元格 $(4, 3)$。

可以证明,在所有可能的山丘中,单元格的最大总值等于 $19$。

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.