Diamonds

View as PDF

Submit solution

Points: 7 (partial)
Time limit: 2.0s
Python 10.0s
Memory limit: 512M
Python 768M

Authors:
Problem type

Bob is playing with a drawing software he recently downloaded. The software loads a 10^5 by 10^5 pixel canvas for him to draw on. The pixel at (r, c) is the r-th pixel from the top and the c-th pixel from the left, 1-indexed.

Bob experimented with many tools, but he is really fascinated with the diamond coloring tool.

The diamond tool takes in a pixel location (x, y) and a weight w. It then colors every pixel within a manhattan distance of w from (x, y). The manhattan distance between two pixels (x_1, y_1) and (x_2, y_2) is |x_1-x_2|+|y_1-y_2|.

Bob uses the diamond tool N times. Can you determine how many pixels are colored?

Note: Python users should consider not using Python

Constraints

1 \le N \le 100

1 \le x, y, w \le 10^5

Subtask 1 [10%]

N = 1

1 \le x, y, w \le 200

Subtask 2 [20%]

1 \le x, y, w \le 200

Subtask 3 [30%]

N = 1

Subtask 4 [40%]

No additional constraints.

Input Specification

The first line of input will contain N.

The next N lines will contain 3 space-separated integers x, y, and w.

Output Specification

Output one integer on one line, the number of colored pixels.

Sample Input

3
2 3 3
8 4 1
4 7 2

Sample Output

38

Explanation

#####.....
##X####...
########..
.#####X##.
..#..###..
......#...
...#......
..#X#.....
...#......
..........

In the above diagram, the #'s represent colored pixels and X's represent the locations where the diamond tool was used (these are also colored).

Note that this is only a 10 by 10 snippet of the full canvas, but the rest of the canvas is empty. We can count 38 colored pixels.


Comments

There are no comments at the moment.