結果

問題 No.859 路線A、路線B、路線C
ユーザー AEnAEn
提出日時 2022-06-24 18:03:56
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 78 ms / 1,000 ms
コード長 1,125 bytes
コンパイル時間 332 ms
コンパイル使用メモリ 87,268 KB
実行使用メモリ 71,636 KB
最終ジャッジ日時 2023-08-08 09:00:46
合計ジャッジ時間 2,913 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 76 ms
71,620 KB
testcase_01 AC 76 ms
71,556 KB
testcase_02 AC 77 ms
71,488 KB
testcase_03 AC 76 ms
71,284 KB
testcase_04 AC 77 ms
71,324 KB
testcase_05 AC 78 ms
71,540 KB
testcase_06 AC 75 ms
71,368 KB
testcase_07 AC 75 ms
71,636 KB
testcase_08 AC 74 ms
71,372 KB
testcase_09 AC 75 ms
71,256 KB
testcase_10 AC 76 ms
71,376 KB
testcase_11 AC 77 ms
71,564 KB
testcase_12 AC 76 ms
71,492 KB
testcase_13 AC 74 ms
71,476 KB
testcase_14 AC 76 ms
71,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from heapq import *

x, y, z = map(int, input().split())
s0,t0 = map(str, input().split())
s1,t1 = map(str, input().split())
INF = float('inf')

v = [[s0,t0],[s1,t1]]
def dijkstra(s, n):
    dist = [INF] * n
    hq = [(0, s)]
    dist[s] = 0
    seen = [False] * n
    # 経路復元用
    # prev = [-1]*n
    while hq:
        dis, v = heappop(hq)
        if dist[v] < dis:
            continue
        seen[v] = True
        for to, cost in G[v]:
            if seen[to] == False and dist[v] + cost < dist[to]:
                dist[to] = dist[v] + cost
                # prev[to] = v
                heappush(hq, (dist[to], to))
    return dist
G = [list() for _ in range(4)]
for a in (x, y, z):
    G[0].append((1, a))
    G[1].append((0, a))
cnt = 2
ans = float('inf') if s0!=s1 else abs(int(t0)-int(t1))
for b, c in v:
    if b == 'A':
        res = x
    elif b == 'B':
        res = y
    else:
        res = z
    G[cnt].append((0, int(c)-0.5))
    G[cnt].append((1%2, res-int(c)+0.5))
    G[0].append((cnt, int(c)-0.5))
    G[1].append((cnt, res-int(c)+0.5))
    cnt += 1
d = dijkstra(2,4)
print(min(ans,int(d[3])))
0