#P11254. Cleaning Robot's Reachable Area
Cleaning Robot's Reachable Area
Cleaning Robot's Reachable Area
Nana's home is represented by a 2D plane of size \(n \times m\) with walls at the boundary. The top-left wall corner is located at \((0,0)\) and the bottom-right wall corner at \((n+1, m+1)\). There are \(k\) pieces of furniture inside the home; each piece occupies exactly one grid point (its coordinate is given).
A circular cleaning robot named Macaron, with radius \(r\), starts at an initial grid point \((x_s,y_s)\) (its center). Macaron can move only in the four cardinal directions (up, down, left, right), and after every move its center must remain on an integer grid point.
However, when moving, Macaron must always ensure that its circular body does not overlap with any furniture or the walls. Overlapping is defined as the interior of the circle having a common point with a furniture point or going beyond the walls. Being tangent (i.e. exactly touching) is allowed. In other words, for any potential robot center \((x,y)\), the following conditions must hold:
- Wall constraints: \(x - r \ge 0\), \(x + r \le n+1\), \(y - r \ge 0\), and \(y + r \le m+1\).
- For each furniture located at \((f_x, f_y)\): \((x - f_x)^2 + (y - f_y)^2 \ge r^2\).
Starting at \((x_s,y_s)\) (which is guaranteed to be a valid position), Macaron cleans all grid points that its center can reach by moving according to the above rules. Your task is to count the number of integer grid points (within the valid region) that Macaron can reach.
Note: Only output the final answer (the count) — Nana need not be informed about these mundane details!
inputFormat
The input is given in the following format:
n m r x_s y_s k f1_x f1_y f2_x f2_y ... (k lines in total)
Where:
- \(n, m, r\) are positive integers where \(n\) and \(m\) define the size of Nana's home and \(r\) is the radius of Macaron.
- \(x_s, y_s\) is the starting grid coordinate of Macaron's center.
- \(k\) is the number of furniture pieces followed by \(k\) lines of coordinates \((f_{ix}, f_{iy})\) for each furniture.
outputFormat
Output a single integer representing the number of grid points (where the center of the robot can reside) that Macaron can reach.
sample
5 5 1
3 3
0
25