Grid
Time limit1sMemory limit128 MB
Given n points, decide whether there exist an axis-aligned grid of evenly spaced lines and a straight line whose intersection set is exactly those points.
- Level
Hard8 of 10
- Topics
- Geometry, Math, Implementation, Brute force
- Solved
- No attempts yet
Problem
Gerald spent several hours drawing a rectangular grid on a sheet of paper. First he drew several vertical lines, keeping the same distance between neighbouring ones. Then he drew several horizontal lines, keeping the same distance between neighbouring ones. Both and are positive, and every line he drew is a full straight line that never ends.
While Gerald was relaxing with a cup of tea, his brother Mike came in and scratched one straight line on the sheet. Gerald felt outraged and ordered Mike to remove everything odd from the paper. Mike rubbed out almost all of the drawing with an eraser, but he did not notice the points where his line crossed the grid, and those points stayed bold enough to read.
Mike copied the surviving points into his notebook, and the brothers now argue about whether that list can be right.
A grid is described by integers , , and , where is a multiple of and is a multiple of . It consists of the vertical lines and the horizontal lines . Mike's line is an arbitrary straight line. The list is right when some grid and some straight line have exactly the listed points in common. Mike's line then cannot lie on top of a grid line, because that would leave infinitely many common points.
Decide whether the list can be right.
Input
The first line contains one integer , the number of points ().
Each of the next lines contains two integers and , the coordinates of one point. Every coordinate is at most in absolute value.
All the points are distinct.
Output
Print YES if such a grid and such a straight line exist, and NO otherwise.