Surveillance Cameras
InterviewTime limit1sMemory limit128 MB
Given up to 50,000 distinct grid points, decide whether three axis-parallel lines (full rows or columns) can cover all of them.
- Level
Medium7 of 10
- Topics
- Brute force, Recursion, Implementation, Geometry
- Solved
- No attempts yet
Problem
Changyoung wants to monitor all of his cows () using three newly purchased surveillance cameras.
The -th cow is located at , where and are integers with . No two cows share the same coordinates.
Each surveillance camera monitors every cow that lies on a single vertical line or a single horizontal line. In other words, one camera covers an entire column or an entire row .
Write a program that determines whether all cows can be monitored using three cameras. Equivalently, decide whether the points in the plane can all be covered by three axis-parallel lines.
Input
The first line contains the number of cows .
Each of the next lines contains the coordinates and of a cow, separated by a space.
Output
Print if all cows can be monitored with three surveillance cameras, and otherwise.
Hint
Suppose there are cows located at , , , , , and . Placing the cameras at , , and monitors every cow, so the answer is .