Rooks
InterviewTime limit2sMemory limit1024 MB
Given two players' rooks on a plane, find each rook that has an opposing rook as its nearest neighbor in the same row or column.
- Level
Medium4 of 10
- Topics
- Sorting, Hash map, Implementation
- Solved
- No attempts yet
Problem
Prof. Pang plays chess against his rival Prof. Shou. They are the only two players in the game. The chessboard is very large and can be viewed as a 2D plane. Prof. Pang placed rooks and Prof. Shou placed rooks. Each rook is a point with integer coordinates on the chessboard. A rook is attacked by another rook if all of the following hold:
- They are placed by different players.
- They have the same x-coordinate or y-coordinate.
- There is no other rook on the line segment between them.
Help Prof. Pang and Prof. Shou decide which rooks are attacked.
Input
The first line contains two integers and (), separated by a single space. They are the number of rooks placed by Prof. Pang and the number of rooks placed by Prof. Shou. The next lines each contain two integers (), separated by a single space, giving the location of one rook placed by Prof. Pang. The next lines follow in the same format for the rooks placed by Prof. Shou. All rooks are at distinct locations.
Output
The first line is a string of length . The -th character is 1 if the -th rook placed by Prof. Pang is attacked, and 0 otherwise. The second line is a string of length . The -th character is 1 if the -th rook placed by Prof. Shou is attacked, and 0 otherwise.