結果
問題 |
No.859 路線A、路線B、路線C
|
ユーザー |
![]() |
提出日時 | 2025-05-14 12:52:09 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,300 bytes |
コンパイル時間 | 257 ms |
コンパイル使用メモリ | 82,168 KB |
実行使用メモリ | 53,760 KB |
最終ジャッジ日時 | 2025-05-14 12:54:02 |
合計ジャッジ時間 | 1,565 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 8 WA * 4 |
ソースコード
x, y, z = map(int, input().split()) S_line, S_num = input().split() S_num = int(S_num) T_line, T_num = input().split() T_num = int(T_num) if S_line == T_line: print(abs(S_num - T_num)) else: # Determine s_last and t_last s_last = x if S_line == 'A' else y if S_line == 'B' else z t_last = x if T_line == 'A' else y if T_line == 'B' else z # Option 1: via first stations cost1 = (S_num - 1) + 1 + (T_num - 1) # Option 2: via last stations cost2 = (s_last - S_num) + 1 + (t_last - T_num) # Option 3: via next line's first and last next_line = {'A': 'B', 'B': 'C', 'C': 'A'}[S_line] if next_line == 'A': next_first, next_last = 1, x elif next_line == 'B': next_first, next_last = 1, y else: next_first, next_last = 1, z cost3 = (S_num - 1) + 1 + (next_last - next_first) + 1 + (t_last - T_num) # Option 4: via previous line's last and first prev_line = {'A': 'C', 'B': 'A', 'C': 'B'}[S_line] if prev_line == 'A': prev_first, prev_last = 1, x elif prev_line == 'B': prev_first, prev_last = 1, y else: prev_first, prev_last = 1, z cost4 = (s_last - S_num) + 1 + (prev_last - prev_first) + 1 + (T_num - 1) min_cost = min(cost1, cost2, cost3, cost4) print(min_cost)