No.325 Manhattan Distance 2
タグ : / 解いたユーザー数 53
作問者 :
Problem Statement
The Manhattan distance between points $(x_1,y_1)$ and $(x_2,y_2)$ is expressed as $|\,x_1-x_2|+|\,y_1-y_2|$.
You are given the bottom-left coordinates $(x_1,y_1)$ and the top-right coordinates $(x_2,y_2)$ of a rectangle.
Find how many lattice points whose Manhattan distance from $(0,0)$ is at most $d$ lie within the closed region of the rectangle enclosed by the four points
$(x_1,y_1), (x_2,y_1), (x_2,y_2), (x_1,y_2)$.
Input
$x_1 \ y_1 \ x_2 \ y_2 \ d$
The bottom-left coordinates $(x_1,y_1)$ of the rectangle, the top-right coordinates $(x_2,y_2)$ of the rectangle, and the Manhattan distance $d$ are given, separated by spaces.
All inputs are integers.
$-10^9 \le x_1 \lt x_2 \le 10^9$
$-10^9 \le y_1 \lt y_2 \le 10^9$
$0 \le d \le 2 \times 10^9$
Output
Output the number of lattice points within the region whose Manhattan distance from $(0,0)$ is at most $d$.
Sample
Sample 1
Input
0 0 3 3 3
Output
10
The following $10$ points: $(0,0),(0,1),(0,2),(0,3),(1,0),(1,1),(1,2),(2,0),(2,1),(3,0)$
Sample 2
Input
-3 -3 0 0 2
Output
6
Sample 3
Input
1 1 3 3 3
Output
3
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。