結果
問題 | No.859 路線A、路線B、路線C |
ユーザー | stng |
提出日時 | 2022-07-24 16:59:48 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 93 ms / 1,000 ms |
コード長 | 877 bytes |
コンパイル時間 | 337 ms |
コンパイル使用メモリ | 86,956 KB |
実行使用メモリ | 71,796 KB |
最終ジャッジ日時 | 2023-09-20 16:39:10 |
合計ジャッジ時間 | 2,725 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge12 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 93 ms
71,536 KB |
testcase_01 | AC | 92 ms
71,796 KB |
testcase_02 | AC | 91 ms
71,780 KB |
testcase_03 | AC | 93 ms
71,576 KB |
testcase_04 | AC | 93 ms
71,704 KB |
testcase_05 | AC | 92 ms
71,592 KB |
testcase_06 | AC | 92 ms
71,724 KB |
testcase_07 | AC | 90 ms
71,652 KB |
testcase_08 | AC | 91 ms
71,576 KB |
testcase_09 | AC | 91 ms
71,640 KB |
testcase_10 | AC | 90 ms
71,724 KB |
testcase_11 | AC | 92 ms
71,532 KB |
testcase_12 | AC | 93 ms
71,656 KB |
testcase_13 | AC | 91 ms
71,496 KB |
testcase_14 | AC | 92 ms
71,692 KB |
ソースコード
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)