Polyomino Powers
Time limit1sMemory limit128 MB
Given a polyomino on a grid up to 10x10, find the smallest k in 2..5 such that the shape is tiled by k translated copies of one smaller polyomino, or report none.
- Level
Hard8 of 10
- Topics
- Brute force, Backtracking, Implementation, Geometry
- Solved
- No attempts yet
Problem
A polyomino is a shape whose basic building block is the unit square. It is a connected figure formed by joining one or more identical squares placed at distinct positions on the regular square grid, so that every square is connected to every other square through a chain of shared edges (shapes joined only at corners are not allowed). The best-known polyominoes are the seven tetrominoes made of four squares (famous from the game Tetris) and the domino made of two squares.
Some polyominoes can be built by taking several copies of a single smaller polyomino and gluing them — using translation only, without rotation or reflection — at different positions in the plane. Such a polyomino is called a power of the smaller one. Formally, a polyomino is a -power if it can be exactly covered, without overlaps, by translated copies of one smaller polyomino.
Input
The first line contains two positive integers and ().
Each of the next lines contains characters describing an grid. Each character is either . or X; an X marks a cell that belongs to the polyomino and a . marks empty space. The X cells form a single polyomino (they are edge-connected).
Output
Print the smallest integer with such that the given polyomino is a -power — that is, the smallest number of translated copies of one smaller polyomino that exactly cover it. If no such exists, print No solution instead.