#P5976. Radiation Color Propagation
Radiation Color Propagation
Radiation Color Propagation
Given a rectangular grid of width \(W\) and height \(H\) (with integer coordinates \(0 \le x < W\) and \(0 \le y < H\)), there are two types of radiation sources on the grid: white
and black
. Each radiation source is given by its coordinates and its radiation range.
A radiation source at \((x_i, y_i)\) with range \(r_i\) affects any grid point \((x, y)\) if and only if \[ \sqrt{(x-x_i)^2+(y-y_i)^2} \leq r_i, \] where the inequality is inclusive.
Every grid point (including the ones with radiation sources) receives radiation from all sources that cover it. Let \(W_{sum}\) be the total number of white sources covering that point, and \(B_{sum}\) be the total number of black sources covering that point. The final color of the point is determined as follows:
- If \(W_{sum} > B_{sum}\), the point becomes white.
- If \(B_{sum} > W_{sum}\), the point becomes black.
- If \(W_{sum} = B_{sum}\), the point remains neutral and is not counted.
Your task is to determine the total number of white points and black points on the grid after all radiation sources have exerted their influence.
Note: All distance comparisons are to be performed using the Euclidean distance, and the inequality is inclusive.
inputFormat
The first line contains two integers \(W\) and \(H\) representing the width and height of the grid.
The second line contains two integers \(N_{white}\) and \(N_{black}\), the number of white and black radiation sources, respectively.
The next \(N_{white}\) lines each contain three integers \(x\), \(y\), and \(r\), indicating the coordinates and radiation range of a white source.
The following \(N_{black}\) lines each contain three integers \(x\), \(y\), and \(r\), indicating the coordinates and radiation range of a black source.
You may assume that all source coordinates lie within the grid \(0 \le x < W\) and \(0 \le y < H\).
outputFormat
Output two integers separated by a space: the total number of white points and the total number of black points on the grid after radiation is applied.
sample
3 3
1 1
1 1 1
0 0 1
3 1