Boardle
InterviewTime limit1sMemory limit256 MB
Given Q directional answers about a hidden treasure on an N by M grid, count the cells where the treasure can still be.
- Level
Easy3 of 10
- Topics
- Intervals, Implementation
- Solved
- No attempts yet
Problem
The Boardle game is played on an grid. The two opposite corners of the grid are and . The treasure is hidden in one of the cells, and you win the game by finding it.
To find the treasure, you asked questions of the following form.
- Relative to the point , in which direction is the treasure?
The answer is one of east, west, south, north, northeast, northwest, southeast, southwest, or same point. East is , west is , north is , and south is . Use the answers to the questions to count the cells where the treasure could still be.
Input
The first line contains two integers and , the size of the grid.
The second line contains the number of questions .
From the third line to line , line gives the information for the -th question in the form . and are the position of the point asked about in the -th question. is an integer from 1 to 9 and corresponds to each direction as shown in the table below.
If , the treasure is in exactly that direction. For example, if , the treasure is directly north of the chosen point, not northwest or northeast of it.
Output
Print the number of cells where the treasure can be. It is guaranteed that at least one candidate cell exists.
Constraints
- ()
- ()
- ()