#C8510. Farm Tiling with Pattern Transformations
Farm Tiling with Pattern Transformations
Farm Tiling with Pattern Transformations
You are given a rectangular farm of size \(M\) rows and \(N\) columns and a planting pattern defined by \(K\) cells with relative coordinates. The pattern can be rotated (by multiples of \(90^\circ\)) and reflected (horizontally) arbitrarily. Your task is to determine whether it is possible to tile the entire farm with copies of one of the pattern variants without overlaps and without leaving any empty cell.
The tiling is possible if and only if:
- The total number of cells \(M \times N\) is divisible by the number of cells in the pattern.
- There exists a variant of the pattern (obtained via rotations and reflections) such that if \(r\) is the maximum row index and \(c\) is the maximum column index in the normalized pattern, then \(M\) is divisible by \(r\) and \(N\) is divisible by \(c\).
Note that the normalization of a pattern shifts it so that its smallest row and column become \(1\). For example, the pattern with cells at \((2,3)\) and \((3,3)\) normalizes to \((1,1)\) and \((2,1)\).
inputFormat
The input is given from stdin and has the following format:
- The first line contains two integers \(M\) and \(N\) separated by a space, representing the number of rows and columns of the farm.
- The second line contains an integer \(K\) representing the number of cells in the planting pattern.
- The next \(K\) lines each contain two integers, representing the relative coordinates \((x, y)\) of each cell in the pattern.
outputFormat
Output to stdout a single line: YES
if it is possible to tile the farm completely using one of the allowed transformations of the pattern; otherwise, output NO
.
3 3
3
1 1
2 1
3 1
YES
</p>