結果

問題 No.126 2基のエレベータ
ユーザー lam6er
提出日時 2025-04-16 16:40:29
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 605 bytes
コンパイル時間 187 ms
コンパイル使用メモリ 81,916 KB
実行使用メモリ 53,580 KB
最終ジャッジ日時 2025-04-16 16:41:22
合計ジャッジ時間 2,195 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 19 WA * 8
権限があれば一括ダウンロードができます

ソースコード

diff #

A, B, S = map(int, input().split())

def compute_b_path_sum(A, B, S):
    min_f = float('inf')
    for X in range(1, 101):
        current = abs(S - X) + abs(A - X) + X
        if current < min_f:
            min_f = current
    return abs(B - S) + min_f

if S == 1:
    sum_down = abs(A - 1) + 1
    dA = abs(A - 1)
    dB = abs(B - 1)
    if dA <= dB:
        sum_up = sum_down
    else:
        sum_up = compute_b_path_sum(A, B, 1)
    print(min(sum_down, sum_up))
else:
    dA = abs(A - S)
    dB = abs(B - S)
    if dA <= dB:
        print(dA + S)
    else:
        print(compute_b_path_sum(A, B, S))
0