結果

問題 No.859 路線A、路線B、路線C
ユーザー gew1fw
提出日時 2025-06-12 21:44:47
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 2,815 bytes
コンパイル時間 279 ms
コンパイル使用メモリ 81,940 KB
実行使用メモリ 54,040 KB
最終ジャッジ日時 2025-06-12 21:49:14
合計ジャッジ時間 1,465 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 4 WA * 8
権限があれば一括ダウンロードができます

ソースコード

diff #

x, y, z = map(int, input().split())
s0, t0 = input().split()
s1, t1 = input().split()
t0 = int(t0)
t1 = int(t1)

if s0 == s1:
    print(abs(t1 - t0))
else:
    candidates = []
    
    # 情况1: A1 -> B1
    a1_start = 0
    if s0 == 'A':
        a1_start = t0 - 1
    elif s0 == 'B':
        a1_start = (t0 - 1) + 1
    elif s0 == 'C':
        a1_start = (t0 - 1) + 1 + 1
    
    b1_end = 0
    if s1 == 'B':
        b1_end = t1 - 1
    elif s1 == 'A':
        b1_end = (t1 - 1) + 1
    elif s1 == 'C':
        b1_end = (t1 - 1) + 1 + 1
    case1 = a1_start + 1 + b1_end
    candidates.append(case1)
    
    # 情况2: B1 -> Cz
    b1_start = 0
    if s0 == 'B':
        b1_start = t0 - 1
    elif s0 == 'A':
        b1_start = (t0 - 1) + 1
    elif s0 == 'C':
        b1_start = (t0 - 1) + 1 + 1
    
    cz_end = 0
    if s1 == 'C':
        cz_end = z - t1
    elif s1 == 'B':
        cz_end = (y - t1) + 1
    elif s1 == 'A':
        cz_end = (x - t1) + 2
    case2 = b1_start + 1 + cz_end
    candidates.append(case2)
    
    # 情况3: Cz -> A1
    cz_start = 0
    if s0 == 'C':
        cz_start = z - t0
    elif s0 == 'B':
        cz_start = (y - t0) + 1
    elif s0 == 'A':
        cz_start = (x - t0) + 2
    
    a1_end = 0
    if s1 == 'A':
        a1_end = t1 - 1
    elif s1 == 'B':
        a1_end = (t1 - 1) + 1
    elif s1 == 'C':
        a1_end = (t1 - 1) + 1 + 1
    case3 = cz_start + 1 + a1_end
    candidates.append(case3)
    
    # 情况4: Ax -> Cz
    ax_start = 0
    if s0 == 'A':
        ax_start = x - t0
    elif s0 == 'B':
        ax_start = (y - t0) + 1 + 1
    elif s0 == 'C':
        ax_start = (z - t0) + 1 + 1
    
    cz_end4 = 0
    if s1 == 'C':
        cz_end4 = z - t1
    elif s1 == 'B':
        cz_end4 = (y - t1) + 1
    elif s1 == 'A':
        cz_end4 = (x - t1) + 2
    case4 = ax_start + 1 + cz_end4
    candidates.append(case4)
    
    # 情况5: By -> Cz
    by_start = 0
    if s0 == 'B':
        by_start = y - t0
    elif s0 == 'A':
        by_start = (x - t0) + 1 + 1
    elif s0 == 'C':
        by_start = (z - t0) + 1 + 1
    
    cz_end5 = 0
    if s1 == 'C':
        cz_end5 = z - t1
    elif s1 == 'B':
        cz_end5 = (y - t1) + 1
    elif s1 == 'A':
        cz_end5 = (x - t1) + 2
    case5 = by_start + 1 + cz_end5
    candidates.append(case5)
    
    # 情况6: Ax -> By
    ax_start6 = 0
    if s0 == 'A':
        ax_start6 = x - t0
    elif s0 == 'B':
        ax_start6 = (y - t0) + 1 + 1
    elif s0 == 'C':
        ax_start6 = (z - t0) + 1 + 1
    
    by_end6 = 0
    if s1 == 'B':
        by_end6 = y - t1
    elif s1 == 'A':
        by_end6 = (x - t1) + 1 + 1
    elif s1 == 'C':
        by_end6 = (z - t1) + 1 + 1
    case6 = ax_start6 + 1 + by_end6
    candidates.append(case6)
    
    min_price = min(candidates)
    print(min_price)
0