結果

問題 No.3680 セグメント釣り
コンテスト
ユーザー Asuka
提出日時 2026-09-05 14:00:30
言語 PyPy3
(7.3.23)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
WA  
実行時間 -
コード長 716 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 230 ms
コンパイル使用メモリ 96,208 KB
実行使用メモリ 86,956 KB
最終ジャッジ日時 2026-09-05 14:01:16
合計ジャッジ時間 7,921 ms
ジャッジサーバーID
(参考情報)
judge5_0 / judge4_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 6 WA * 7
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

t = int(input())
for _ in range(t):
    sx, sy, tx, ty = map(int, input().split())
    
    if sy > ty:
        sx, sy, tx, ty = tx, ty, sx, sy
    
    ans = 0
    ans += (ty - sy)
    
    min_cost = 10**50
    if ty >= 300:
        min_cost = 0
    else:
        for i in range(500):
            x1 = min(sx, tx)
            x2 = max(sx, tx)

            cost = (2 * i)
            j = i + ty
            if x1 // 2**j == x2 // 2**j:
                pass
            else:
                nx = 2**j * ((x1 + 2**j - 1) // 2**j)
                cost += 1 + abs(x2 - nx) // 2**j

            min_cost = min(min_cost, cost)
            if x1 // 2**j == x2 // 2**j:
                break
    
    print(ans + min_cost)
0