God Save the i-th Queen
InterviewTime limit1sMemory limit128 MB
Given a board and placed queens, count empty squares not sharing a row, column, or diagonal with any queen.
- Level
Medium5 of 10
- Topics
- Array, Hash map, Math, Implementation
- Solved
- No attempts yet
Problem
Every year at the ACM-ICPC World Finals a large chessboard is set up so the contestants can play against one another. In this problem we check your basic chess intuition.
Recall that a queen attacks along its row, its column, and both diagonals.
A chessboard already holds queens. Your task is to count the squares on which the -th queen could be placed so that it is not attacked by any of the queens already on the board. A candidate square must be empty and must not share a row, a column, or a diagonal with any existing queen.
Input
The input consists of several tasks.
Each task begins with a line of three integers , , separated by spaces. and give the board size, with . is the number of queens already placed, with .
The next lines each contain two integers and (, ), the position of the -th queen. All positions are distinct, i.e. no two queens share the same square.
The last task is followed by a line containing three zeros, which is not processed.
Output
For each task, print one line with a single integer: the number of empty squares that do not share a row, a column, or a diagonal with any queen already on the board.