結果

問題 No.859 路線A、路線B、路線C
ユーザー kekure
提出日時 2019-08-15 23:13:46
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 28 ms / 1,000 ms
コード長 1,382 bytes
コンパイル時間 358 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 11,008 KB
最終ジャッジ日時 2024-09-19 15:49:26
合計ジャッジ時間 1,135 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 12
権限があれば一括ダウンロードができます

ソースコード

diff #

A, B, C = map(int, input().split())
station_s, no_s = input().split()
station_e, no_e = input().split()
no_s = int(no_s)
no_e = int(no_e)
# Aから小さい順になるように数値変換

a = ['A', 'B', 'C']
temp = 'ABC'
if A > B:
    A, B = B, A
    a[0], a[1] = a[1], a[0]
if B > C:
    B, C = C, B
    a[1], a[2] = a[2], a[1]
if A > B:
    A, B = B, A
    a[0], a[1] = a[1], a[0]

station_s = temp[a.index(station_s)]
station_e = temp[a.index(station_e)]
if temp.index(station_s) > temp.index(station_e):
    station_s, station_e = station_e, station_s
    no_s, no_e = no_e, no_s

ans = 0
if station_s == 'A':
    if station_e == 'A':
        tyoku = abs(no_s - no_e)
        ans = tyoku
    if station_e == 'B':
        ans = min(no_s + no_e - 1, A - no_s + B - no_e + 1)
    elif station_e == 'C':
        ans = min(no_s + no_e - 1, A - no_s + C - no_e + 1)

elif station_s == 'B':
    if station_e == 'B':
        tyoku = abs(no_s - no_e)
        s = sorted([no_s, no_e])
        keiyu = C + s[0] + A - s[1]
        ans = min(tyoku, keiyu)
    if station_e == 'C':
        not_a_keiyu = min(no_s + no_e - 1, B - no_s + C - no_e + 1)
        a_keiyu = min(no_s + A + C - no_e, B - no_s + A + no_e)
        ans = min(not_a_keiyu, a_keiyu)
else:
    tyoku = abs(no_s - no_e)
    s = sorted([no_s, no_e])
    keiyu = s[0] + C + A - s[1]
    ans = min(tyoku, keiyu)

print(ans)
0