結果

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

ソースコード

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(t0 - t1))
else:
    # 计算所有可能的中转点
    # 中转点列表:A1, Ax, B1, By, C1, Cz
    # 对每个中转点计算票价
    min_cost = float('inf')
    
    # 起点在S0线的t0,终点在S1线的t1
    # 对每个中转点计算起点到中转点的票价,加上终点到中转点的票价
    # 中转点1:A1
    if S0 == 'A':
        cost0_a1 = abs(t0 - 1)
    else:
        # 起点不在A线,到A1的票价是无穷大?或者无法到达?
        # 这里假设不能直接到达,所以只考虑A线的中转点是否为起点所在线
        cost0_a1 = float('inf')
    if S1 == 'A':
        cost1_a1 = abs(t1 - 1)
    else:
        cost1_a1 = float('inf')
    total_a1 = cost0_a1 + cost1_a1
    if total_a1 < min_cost:
        min_cost = total_a1
    
    # 中转点2:Ax
    if S0 == 'A':
        cost0_ax = abs(t0 - x)
    else:
        cost0_ax = float('inf')
    if S1 == 'A':
        cost1_ax = abs(t1 - x)
    else:
        cost1_ax = float('inf')
    total_ax = cost0_ax + cost1_ax
    if total_ax < min_cost:
        min_cost = total_ax
    
    # 中转点3:B1
    if S0 == 'B':
        cost0_b1 = abs(t0 - 1)
    else:
        cost0_b1 = float('inf')
    if S1 == 'B':
        cost1_b1 = abs(t1 - 1)
    else:
        cost1_b1 = float('inf')
    total_b1 = cost0_b1 + cost1_b1
    if total_b1 < min_cost:
        min_cost = total_b1
    
    # 中转点4:By
    if S0 == 'B':
        cost0_by = abs(t0 - y)
    else:
        cost0_by = float('inf')
    if S1 == 'B':
        cost1_by = abs(t1 - y)
    else:
        cost1_by = float('inf')
    total_by = cost0_by + cost1_by
    if total_by < min_cost:
        min_cost = total_by
    
    # 中转点5:C1
    if S0 == 'C':
        cost0_c1 = abs(t0 - 1)
    else:
        cost0_c1 = float('inf')
    if S1 == 'C':
        cost1_c1 = abs(t1 - 1)
    else:
        cost1_c1 = float('inf')
    total_c1 = cost0_c1 + cost1_c1
    if total_c1 < min_cost:
        min_cost = total_c1
    
    # 中转点6:Cz
    if S0 == 'C':
        cost0_cz = abs(t0 - z)
    else:
        cost0_cz = float('inf')
    if S1 == 'C':
        cost1_cz = abs(t1 - z)
    else:
        cost1_cz = float('inf')
    total_cz = cost0_cz + cost1_cz
    if total_cz < min_cost:
        min_cost = total_cz
    
    print(min_cost)
0