QOJ.ac

QOJ

Time Limit: 1.0 s Memory Limit: 512 MB Total points: 100 Hackable ✓

#7149. 牆

Statistics

可憐嘅 bobo 畀迷宮困住咗!

迷宮分成 $n$ 行同 $m$ 列。迷宮每個格仔都有一道沿對角線嘅牆。所以格仔只有兩種類型。

靠住 bobo 嘅魔法,佢可以用 $c_{i,j}$ 嘅代價改變格仔 $(i, j)$ 嘅類型。作為一位善良嘅魔法師,bobo 想令呢個迷宮唔會再困住人。即係話,唔可以有任何畀牆圍住嘅封閉區域。

求 bobo 達成目標所需嘅最小總代價。

輸入格式

第一行有 2 個整數 $n, m$($1 \le n, m \le 1000$)。

之後 $n$ 行,每行有 $m$ 個字元,表示格仔入面道牆嘅方向。

最後 $n$ 行,每行有 $m$ 個整數 $c_{i,1}, c_{i,2}, \ldots, 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.