Walls
시간 제한2초메모리 제한1024 MB
각 칸에 두 방향 중 하나의 대각선 벽이 있고 뒤집는 비용이 주어질 때, 벽으로 둘러싸인 닫힌 영역이 생기지 않도록 하는 최소 비용을 구한다.
문제
Poor bobo is trapped in a maze!
The maze is divided into rows and columns. Each cell of the maze contains a wall across the diagonal. Thus, there are only two types of cells.
Thanks to bobo's magic power, he can change the type of cell with cost . As a kind magician, bobo would like to make the maze unable to trap people anymore. That is to say, there will be no closed area surrounded by walls.
Find the minimum total cost for bobo to achieve the goal.
입력
The first line contains integers ().
Each of the following lines contains characters, which denotes the direction of wall in the cell.
Each of the last lines contains integers ().
출력
A single number denotes the minimum of cost.