結果

問題 No.859 路線A、路線B、路線C
ユーザー maspymaspy
提出日時 2020-02-05 10:15:10
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 33 ms / 1,000 ms
コード長 748 bytes
コンパイル時間 320 ms
コンパイル使用メモリ 11,892 KB
実行使用メモリ 10,112 KB
最終ジャッジ日時 2023-10-22 03:49:56
合計ジャッジ時間 1,540 ms
ジャッジサーバーID
(参考情報)
judge9 / judge10
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

xyz = map(int,readline().split())
ST = read().decode().split()

length = {a : x for a, x in zip('ABC', xyz)}

def f(S0, T0, S1, T1):
    T0 = int(T0)
    T1 = int(T1)
    if S0 == S1:
        yield abs(T0 - T1)
    # 2つの交差点 L, R。計算の都合、交差点にも駅があるとしておく。
    L0, R0 = T0, length[S0] + 1 - T0
    L1, R1 = T1, length[S1] + 1 - T1
    D = min(length.values()) + 1
    # 両方を通る場合
    yield L0 + R1 + D - 2
    yield L1 + R0 + D - 2
    # L のみを通る場合
    yield L0 + L1 - 1
    # R のみを通る場合
    yield R0 + R1 - 1

answer = min(f(*ST))
print(answer)
0