Decide whether a grid of dots and empty cells can be tiled by four line-piece types so that lines match across shared sides and never touch the border.
Hard8GraphDFSBacktrackingCombinatoricsNo attempts yetTime limit1sMemory limit1024 MBEve loves puzzles. The one she bought recently has turned out to be hard. The puzzle is a rectangular grid with R rows and C columns. Some cells carry a dot and the rest are empty. Four types of pieces come with the puzzle, and there are R×C units of each type.

Every piece carries a line drawing. A type 1 piece has a dot inside the cell, and a line runs from that dot to the midpoint of one side. A type 2 piece is a straight line joining the midpoints of two opposite sides. A type 3 piece is a bent line joining the midpoints of two adjacent sides. A type 4 piece leaves one side, loops around inside the cell and returns to the same side, so its line meets that side at two points. Those two points are not the midpoint of the side; they sit apart from each other on either side of it.
The objective is to use some of the pieces to fill the grid completely, so that every cell is covered by one piece. A piece may be rotated by 90, 180 or 270 degrees. Three constraints must be respected:
Eve suspects the puzzle was built sloppily and has no solution at all. Decide whether the puzzle can be solved.
The first line contains two integers R and C (1≤R,C≤20), the number of rows and the number of columns of the puzzle. Each of the next R lines contains a string of C characters describing one row of the grid. The lowercase letter o marks a cell with a dot, and the hyphen - marks an empty cell. At most 15 cells carry a dot.
Print a single line with the uppercase letter Y if the puzzle can be solved as described, and the uppercase letter N otherwise.