Turning off lights

Suppose that each cell in an n×mn \times m board has a light that can be off or on. Furthermore, every cell has a switch that changes the state of the (at most) 8 neighboring lights, and also the state of the light in the same cell. Compute how many switches must be pressed to turn off all the lights.

Input

Input consists of several cases, each with the dimensions nn and mm, both between 2 and 5, followed by nn rows with mm characters each. A point indicates a light that is off, and an asterisk a light that is on.

Output

For every case, print the minimum number of switches to be pressed to turn off all the lights. If it is impossible, print “no”.

Observation

The expected solution to this problem is a “reasonably” pruned backtracking.

Problem information

Author: Unknown
Translator: Salvador Roura

Generation: 2026-01-25T11:17:58.926Z

© Jutge.org, 2006–2026.
https://jutge.org