Turn on the lamp
Stepan is designing an electronic circuit on a rectangular grid of size , consisting of square tiles. Each of the squares has a wire connecting two opposite corners.
The power source is connected to the top-left corner of the grid, and the lamp is connected to the bottom-right corner. To turn on the lamp, any tile can be rotated degrees in either direction.
In the image, the lamp is off. If any tile in the second-to-last column on the right is rotated, the lamp will turn on.
Write a program that determines the minimum number of tiles that need to be rotated to turn on the lamp.
Input
The first line contains two integers and — the grid dimensions. The following lines contain characters: either the symbol '\' or '/', indicating the wire direction on each tile.
Output
Output the minimum number of rotations required to turn on the lamp, or the message "NO SOLUTION" if it is impossible to turn on the lamp.