QOJ.ac

QOJ

حد الوقت: 1.0 s حد الذاكرة: 512 MB مجموع النقاط: 100 قابلة للهجوم ✓

#7149. 墙

الإحصائيات

可怜的 bobo 被困在迷宫里了!

迷宫被划分为 $n$ 行 $m$ 列。迷宫的每个单元格中都有一堵沿对角线方向的墙。因此,单元格只有两种类型。

多亏了 bobo 的魔法,他可以花费 $c_{i,j}$ 的代价改变单元格 $(i, j)$ 的类型。作为一名善良的魔法师,bobo 希望让迷宫不再困住任何人。也就是说,迷宫中将不存在被墙围成的封闭区域。

请计算 bobo 实现这一目标所需的最小总代价。

输入格式

第一行包含两个整数 $n, m$ ($1 \le n, m \le 1000$)。

接下来 $n$ 行,每行包含 $m$ 个字符,表示单元格中墙的方向。

最后 $n$ 行,每行包含 $m$ 个整数 $c_{i,1}, c_{i,2}, \dots, c_{i,m}$ ($1 \le c_{i,j} \le 1000$)。

输出格式

输出一个整数,表示最小代价。

样例

样例输入 1

3 3
/\/
\/\
/\/
1 3 3
3 1 3
3 3 3

样例输出 1

2

样例输入 2

2 2
\/
/\
1000 1000
1000 1000

样例输出 2

0

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.