Alice Through the Looking Glass
InterviewTime limit2sMemory limit512 MB
Given a magnification level and a cell coordinate, decide whether that cell of the 5^m by 5^m self-similar grid is filled or empty.
- Level
Medium5 of 10
- Topics
- Recursion, Divide and conquer, Implementation
- Solved
- No attempts yet
Problem
Alice is looking at a crystal through a microscope. Her microscope has an interesting feature: it can superimpose grid lines over the image she is looking at.
At magnification level 1, Alice sees the image below, with a grid superimposed over it.

As Alice increases the magnification, the leaf-like pattern becomes more intricate. At magnification level 2 she sees the image with a grid, and the crystal repeats its own shape at a smaller scale, stacked on top of itself.

This self-similarity repeats at every magnification level. In general, at magnification level the microscope shows a grid.
Alice's microscope supports up to 13 levels of magnification, and she would like to determine, for any grid cell, whether it is filled with crystal.
The grid cells are labeled so that the bottom-left cell is , the bottom-right cell is , the top-left cell is , and the top-right cell is .
Given a magnification level () and a grid position with and , determine whether that grid cell is filled with crystal or is empty space.
Input
The first line contains an integer (), the number of queries. Each of the next lines contains three integers , , and : the magnification level and the position of the grid cell Alice wishes to examine.
Output
Print lines. For each query, print crystal if the specified grid cell contains crystal, or empty if it is empty space.