QOJ.ac

QOJ

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

#7149. 壁

Statistics

かわいそうな bobo は迷路に閉じ込められています!

迷路は $n$ 行 $m$ 列に分かれています。迷路の各マスには対角線に沿って壁があります。したがって、マスの種類は 2 種類だけです。

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 つ出力してください。

入出力例

入力 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.