結果

問題 No.2213 Neq Move
ユーザー Shirotsume
提出日時 2023-01-15 20:21:21
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 56 ms / 2,000 ms
コード長 884 bytes
コンパイル時間 168 ms
コンパイル使用メモリ 81,920 KB
実行使用メモリ 63,104 KB
最終ジャッジ日時 2024-07-07 15:07:25
合計ジャッジ時間 897 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 5
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
from collections import deque, Counter
input = lambda: sys.stdin.readline().rstrip()
ii = lambda: int(input())
mi = lambda: map(int, input().split())
li = lambda: list(mi())
inf = 2 ** 63 - 1
mod = 998244353

def solve():
    a, b, c, d = mi()
    if a > b:
        a, b = b, a
        c, d = d, c
    if a <= c and b <= d and c < d:
        print(c - a + d - b)
    elif a <= c and b <= d and c > d:
        print(1 + d + (c - a))
    elif a > c and b > d:
        print(2 + c + d)
    elif a <= c and b > d and c < d:
        if a == 1:
            print(3 + c + d)
        else:
            print(2 + c + d)
    elif a <= c and b > d and c > d:
        print(c - a + 1 + d)
    elif a > c and b <= d and c < d:
        print(1 + c + d - b)
    elif a > c and b <= d and c > d:
        print(2 + c + d)
    else:
        raise Exception

for _ in range(ii()):
    solve()
0