結果
| 問題 |
No.859 路線A、路線B、路線C
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2022-07-24 16:53:08 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 842 bytes |
| コンパイル時間 | 152 ms |
| コンパイル使用メモリ | 82,264 KB |
| 実行使用メモリ | 66,036 KB |
| 最終ジャッジ日時 | 2024-07-06 11:37:33 |
| 合計ジャッジ時間 | 1,377 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 9 WA * 1 RE * 2 |
ソースコード
from collections import deque
xyz = [int(i) for i in input().split()]
srt = input().split()
end = input().split()
abc = [[10**10]*2 for i in range(3)]
idx = ord(srt[0])-ord("A")
d = deque()
abc[idx][0] = int(srt[1])-1
abc[idx][1] = xyz[idx] - int(srt[1])
d.append([idx,0])
d.append([idx,1])
while len(d):
idx,pos = d.popleft()
for i in range(3):
if i == idx:
continue
if abc[i][pos] > abc[idx][pos]+1:
abc[i][pos] = abc[idx][pos]+1
d.append([i,pos])
if abc[i][1-pos] > abc[idx][pos]+xyz[idx]:
abc[i][1-pos] = abc[idx][pos]+xyz[idx]
d.append([i,1-pos])
idxend = ord(end[0])-ord("A")
ans = min(int(end[1]) + abc[idxend][0] - 1,xyz[idxend] - int(end[1]) + abc[idxend][1])
if idx == idxend:
ans = min(ans,abs(int(srt[0])-int(srt[1])))
print(ans)