QOJ.ac

QOJ

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

#7149. Những bức tường

Statistics

bobo tội nghiệp đang bị mắc kẹt trong một mê cung!

Mê cung được chia thành $n$ hàng và $m$ cột. Mỗi ô của mê cung chứa một bức tường dọc theo đường chéo. Do đó, chỉ có hai loại ô.

Nhờ sức mạnh phép thuật, bobo có thể thay đổi loại của ô $(i, j)$ với chi phí $c_{i,j}$. Là một pháp sư tốt bụng, bobo muốn khiến mê cung không còn có thể giam giữ bất kỳ ai nữa. Nói cách khác, sẽ không có vùng kín nào được bao quanh bởi các bức tường.

Hãy tìm tổng chi phí nhỏ nhất để bobo đạt được mục tiêu.

Dữ liệu vào

Dòng đầu tiên chứa 2 số nguyên $n, m$ ($1 \le n, m \le 1000$).

Mỗi dòng trong $n$ dòng tiếp theo chứa $m$ ký tự, biểu thị hướng của bức tường trong ô.

Mỗi dòng trong $n$ dòng cuối chứa $m$ số nguyên $c_{i,1}, c_{i,2}, \ldots, c_{i,m}$ ($1 \le c_{i,j} \le 1000$).

Dữ liệu ra

Một số duy nhất biểu thị chi phí nhỏ nhất.

Ví dụ

Dữ liệu vào 1

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

Dữ liệu ra 1

2

Dữ liệu vào 2

2 2
\/
/\
1000 1000
1000 1000

Dữ liệu ra 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.