問題一覧 > 通常問題

No.325 Manhattan Distance 2

レベル : / AI推定難易度 : 1425 / 実行時間制限 : 1ケース 1.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 53
作問者 : kzyKT
お気に入りにしたユーザー ProblemId : 477 / 自分の提出
問題文最終更新日: 2026-06-25 04:33:04
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
Advent Calendar Contest 2015 (順位表) の他の問題:

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もしくは右上の雲マークをクリックしてアカウントを作成してください。