問題一覧 > 通常問題

No.2213 Neq Move

レベル : / AI推定難易度 : 1750 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 65
作問者 : Shirotsume / テスター : 👑 AngrySadEight ygussany
お気に入りにしたユーザー ProblemId : 8538 / 自分の提出
問題文最終更新日: 2023-02-04 13:18:40
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 376 (順位表) の他の問題:

Problem Statement

You are given positive integers $A, B, C, D$. It is guaranteed that $A \neq B$ and $C \neq D$.

There are $2$ variables $x, y$. Initially, $x = A$ and $y = B$. You may perform the following operation any number of times.

  • Choose $1$ of the following and perform it.
    • Replace $x$ with $x + 1$.
    • Replace $y$ with $y + 1$.
    • Replace $x$ with $0$.
    • Replace $y$ with $0$.

However, you cannot perform an operation that would result in $x = y$ after the operation.

Your goal is to bring the variables $x,y$ to the state where $x = C$ and $y = D$. Find the minimum possible number of operations required to achieve the goal.

You are given $T$ test cases; solve each of them.

Constraints

  • All input values are integers.
  • $1 \leq T \leq 1000$
  • $1 \leq A, B, C, D \leq 10^9$
  • $A \neq B$
  • $C \neq D$

Input

The input is given from Standard Input in the following format.

$T$
$\mathrm{case}_1$
$\mathrm{case}_2$
$\vdots$
$\mathrm{case}_T$

Each test case is given in the following format.

$A$ $B$ $C$ $D$

Output

Print $T$ lines. On the $i$-th line, print the minimum number of operations for the $i$-th test case.

Sample

Sample 1
Input
7
1 2 2 1
3 1 2 1
8 4 6 4
5 1 6 7
832898397 796173979 178042403 962556773
988869833 678215128 75264584 244029832
607250193 432233651 617970570 520907159
Output
3
6
12
13
344425198
319294418
99393885

$1$st test case: By operating as $(1,2) \rightarrow (1,0) \rightarrow (2,0) \rightarrow (2, 1)$, the goal can be achieved in $3$ operations.

$2$nd test case: By operating as $(3,1) \rightarrow (0,1) \rightarrow (0,2) \rightarrow (1,2) \rightarrow (1,0) \rightarrow (2,0) \rightarrow (2,1)$, the goal can be achieved in $6$ operations.

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