Circles on a Screen
Time limit3sMemory limit256 MB
Given up to 100 circles drawn on a w×h grid, count how many pixels remain black after the union of circles is painted white.
- Level
Medium5 of 10
- Topics
- Geometry, Simulation, Implementation
- Solved
- No attempts yet
Problem
Andrew wrote a program that draws white circles on a black screen. The screen is monochrome and has a resolution of pixels. Pixels are numbered from the upper-left corner to the bottom-right corner .
A circle with its center at pixel and radius consists of every pixel such that . If a circle does not fit on the screen, the part that falls outside is cut off. A pixel that belongs to at least one circle is white.

Andrew liked the resulting picture and wants to copy it onto his wall. The wall is white and he can only paint some pixels black, so he needs to know how much black paint he will use. He copies the picture exactly, pixel by pixel. Write a program that counts how many black pixels remain on the screen after all circles have been drawn.
Input
The first line contains three integers , , and (; ). Each of the next lines describes one circle with three integers , , and (; ; ): a circle centered at pixel with radius .
Output
Output a single integer: the number of black pixels that remain on the screen.
Hint
The illustration above corresponds to the second example.