問題一覧 > 通常問題

No.208 King

レベル : / AI推定難易度 : 600 / 実行時間制限 : 1ケース 1.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 380
作問者 : kzyKT
お気に入りにしたユーザー ProblemId : 487 / 自分の提出
問題文最終更新日: 2026-06-25 11:43:41
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
yukicoder contest 104 (順位表) の他の問題:

Problem Statement

The king piece in shogi can move $1$ square in any of $8$ directions.
When it is at $(0,0)$, it can move to any of $(-1,1),(0,1),(1,1),(-1,0),(1,0),(-1,-1),(0,-1),(1,-1)$.
The king is currently on the square $(0,0)$.
You want to move it to the square $(x,y)$ as quickly as possible.
However, an allied pawn is at $(x_2,y_2)$ and is in the way.
Find the minimum number of moves to go from $(0,0)$ to $(x,y)$.
Note that the pawn cannot be moved.
This shogi board is infinitely large, and squares with negative coordinates also exist. (Negative coordinates are not given in the input.)

Input

$x \ y$
$x_2 \ y_2$

Line $1$ contains the coordinates of the destination square, separated by a space.
Line $2$ contains the coordinates of the square where the pawn is, separated by a space.

$0 \le x,y,x_2,y_2 \le 10^9$
$(0,0),(x,y),(x_2,y_2)$ are all distinct.

Output

Output the minimum number of moves to reach $(x,y)$.

Sample

Sample 1
Input
1 1
1 0
Output
1

Sample 2
Input
10 1
1 0
Output
10

提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。