結果

問題 No.859 路線A、路線B、路線C
ユーザー qwewe
提出日時 2025-04-24 12:17:14
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 631 bytes
コンパイル時間 424 ms
コンパイル使用メモリ 82,532 KB
実行使用メモリ 53,388 KB
最終ジャッジ日時 2025-04-24 12:17:16
合計ジャッジ時間 1,665 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 7 WA * 5
権限があれば一括ダウンロードができます

ソースコード

diff #

x, y, z = map(int, input().split())
s_line, s_num = input().split()
s_num = int(s_num)
t_line, t_num = input().split()
t_num = int(t_num)

if s_line == t_line:
    print(abs(s_num - t_num))
else:
    # Determine R_end and Q_end based on the lines
    r_end = x if s_line == 'A' else y if s_line == 'B' else z
    q_end = x if t_line == 'A' else y if t_line == 'B' else z

    cost1 = (s_num - 1) + 1 + (t_num - 1)
    cost2 = (r_end - s_num) + 1 + (q_end - t_num)
    cost3 = (s_num - 1) + 1 + 1 + (q_end - t_num)
    cost4 = (r_end - s_num) + 1 + 1 + (t_num - 1)

    min_cost = min(cost1, cost2, cost3, cost4)
    print(min_cost)
0