結果

問題 No.859 路線A、路線B、路線C
ユーザー stngstng
提出日時 2022-07-24 16:53:08
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 842 bytes
コンパイル時間 302 ms
コンパイル使用メモリ 87,144 KB
実行使用メモリ 79,876 KB
最終ジャッジ日時 2023-09-20 16:32:24
合計ジャッジ時間 3,209 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 95 ms
71,428 KB
testcase_01 AC 94 ms
71,392 KB
testcase_02 AC 100 ms
71,384 KB
testcase_03 RE -
testcase_04 AC 96 ms
71,824 KB
testcase_05 AC 94 ms
71,636 KB
testcase_06 AC 95 ms
71,736 KB
testcase_07 AC 94 ms
71,712 KB
testcase_08 AC 97 ms
71,740 KB
testcase_09 AC 98 ms
71,820 KB
testcase_10 AC 96 ms
71,736 KB
testcase_11 WA -
testcase_12 RE -
testcase_13 AC 96 ms
71,832 KB
testcase_14 AC 101 ms
71,728 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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)
0