QOJ.ac

QOJ

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

#7149. קירות

Statistics

bobo המסכן לכוד במבוך!

המבוך מחולק ל־$n$ שורות ול־$m$ עמודות. בכל תא במבוך יש קיר לאורך אחד האלכסונים. לכן יש רק שני סוגי תאים.

בזכות כוח הקסם שלו, bobo יכול לשנות את סוג התא $(i, j)$ בעלות $c_{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.