結果
問題 |
No.859 路線A、路線B、路線C
|
ユーザー |
|
提出日時 | 2022-07-24 16:59:48 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 35 ms / 1,000 ms |
コード長 | 877 bytes |
コンパイル時間 | 316 ms |
コンパイル使用メモリ | 82,244 KB |
実行使用メモリ | 55,324 KB |
最終ジャッジ日時 | 2024-07-06 11:44:03 |
合計ジャッジ時間 | 1,400 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 12 |
ソースコード
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): idx1,pos = d.popleft() for i in range(3): if i == idx1: continue if abc[i][pos] > abc[idx1][pos]+1: abc[i][pos] = abc[idx1][pos]+1 d.append([i,pos]) if abc[i][1-pos] > abc[idx1][pos]+xyz[idx1]: abc[i][1-pos] = abc[idx1][pos]+xyz[idx1] 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]) #print(idx,idxend,srt,end) if idx == idxend: ans = min(ans,abs(int(srt[1])-int(end[1]))) print(ans)