Consider an chess board, where some cells are legal and some are prohibited. You have many small bishops, so tiny that an unbounded number of them fit in every cell. As expected, bishops can only move diagonally. For every given board description, tell if there is a way to (repeatedly) move as many bishops as needed, never passing a prohibited cell, so that eventually all the legal cells have the same number of bishops.
Input begins with a number
,
followed by
cases. Every case begins with the number of rows
and the number of columns
.
Follow
lines, each with
items
separated with spaces. Prohibited cells are marked with an
‘X’. For legal cells, its initial number of bishops is
given. No cell has more than 1000 bishops. Assume
.
For every case, print its number followed by “yes” or
“no”, depending on whether it is possible to move the
bishops so that eventually all the legal cells have the same number.
Input
5 3 9 0 X X X 4 X X X 8 X 1 X 3 X 5 X 7 X X X 2 X X X 6 X X 2 8 X 1 X 1 X 3 X 3 X X 1 X X X 3 X 2 2 X 9 8 X 1 1 X 2 9 500 1000 500 1000 1000 1000 500 1000 500 X X 0 X 0 0 0 500 0
Output
Case 1: yes Case 2: no Case 3: no Case 4: yes Case 5: yes