結果

問題 No.859 路線A、路線B、路線C
ユーザー kekurekekure
提出日時 2019-08-15 22:56:25
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 1,382 bytes
コンパイル時間 100 ms
コンパイル使用メモリ 11,924 KB
実行使用メモリ 10,244 KB
最終ジャッジ日時 2023-10-19 19:33:59
合計ジャッジ時間 1,265 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 29 ms
10,188 KB
testcase_01 AC 29 ms
10,188 KB
testcase_02 AC 30 ms
10,188 KB
testcase_03 AC 30 ms
10,188 KB
testcase_04 AC 29 ms
10,188 KB
testcase_05 AC 29 ms
10,188 KB
testcase_06 AC 30 ms
10,188 KB
testcase_07 AC 29 ms
10,188 KB
testcase_08 AC 30 ms
10,188 KB
testcase_09 AC 29 ms
10,188 KB
testcase_10 WA -
testcase_11 AC 30 ms
10,188 KB
testcase_12 AC 30 ms
10,188 KB
testcase_13 AC 30 ms
10,188 KB
testcase_14 AC 30 ms
10,188 KB
権限があれば一括ダウンロードができます

ソースコード

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 + C + 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