Filling a Board with N-Ominoes
Time limit5sMemory limit512 MB
For each case with piece size X and board R by C, decide whether Richard has an X-omino that blocks every tiling or Gabriel tiles the board anyway.
- Level
Medium6 of 10
- Topics
- Game theory, Geometry, Math
- Solved
- No attempts yet
Problem
An N-omino is a flat shape made of unit squares joined edge to edge. A 1-omino is a single square. An N-omino is an (N-1)-omino with one more square attached along an edge. Two N-ominoes count as the same shape when one can be rotated or flipped onto the other.
The five possible 4-ominoes are shown below.

Some of the 108 7-ominoes are shown below.

Richard and Gabriel play the following game for fixed , and .
- Richard chooses one of the possible X-ominoes.
- Gabriel fills the board with X-ominoes so that no cell is left empty and no piece sticks out. He must use at least one copy of the X-omino Richard chose, and every piece may be rotated or flipped.
Gabriel wins if he fills the board under these rules, and Richard wins if Gabriel cannot. Given , and , decide which player wins.
Input
The first line contains the number of test cases .
Each of the next lines contains , and , separated by spaces.
,
Output
For each test case, print one line in the form Case #x: y. Here is the test case number starting from 1. If at least one X-omino guarantees a win for Richard, is RICHARD. If no such X-omino exists, is GABRIEL.
Hint
In test case 1 of the sample, the only 2-omino Richard can choose is the rectangle. Two of those rectangles always fill a board, so Gabriel wins.
In test case 2 the only choice is again the rectangle. Wherever Gabriel puts it on a board, one cell is left over, so Richard wins.
In test case 3 Richard chooses the 4-omino shaped like a square. It has nowhere to go on a board, so Richard wins.
In test case 4 Richard can choose the straight tromino or the L shaped tromino. In both cases Gabriel fills the board with two copies of the same shape, so Gabriel wins.