This page is still under construction.

Parts of this page are still being built. What you see may change.

Square or Rectangle?

Time limit1sMemory limit512 MB

Summary
A hidden axis-aligned square or rectangle covers at least 4% of a 100x100 grid; locate its edges with limited point queries and decide which shape it is.
Level

Medium7 of 10

Topics
Geometry, Binary search, Implementation
Solved
No attempts yet

Problem

I can be a square, or a rectangle. Am I a square, or a rectangle?

Consider a grid of N×NN \times N squares. Suppose there is either a square or a rectangle covering some grid squares, and each grid square is either completely inside or outside the shape, i.e. the boundary of the shape follows the grid lines. Two examples are shown below:

Figure 1: I am a square.Figure 2: I am a rectangle.

It is also guaranteed that the shape covers at least 4% of the total area of the grid. Your task is to determine if the shape is a square, or a rectangle. To do that, you are allowed to ask at most QQ queries, each query allows you to find out if a certain grid square is inside the shape. The grid squares are identified by coordinates (x,y)(x, y) where 1≤x,y≤N1 \le x, y \le N.

Constraints

  • N=100N = 100
  • 1≤T≤10001 \le T \le 1000

Examples1

  1. Example 1

    Input
    1
    1 1 20 20
    
    Expected output
    square