結果
| 問題 |
No.859 路線A、路線B、路線C
|
| コンテスト | |
| ユーザー |
AEn
|
| 提出日時 | 2022-06-24 18:03:56 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 50 ms / 1,000 ms |
| コード長 | 1,125 bytes |
| コンパイル時間 | 230 ms |
| コンパイル使用メモリ | 82,304 KB |
| 実行使用メモリ | 53,120 KB |
| 最終ジャッジ日時 | 2024-11-08 14:43:51 |
| 合計ジャッジ時間 | 1,758 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 12 |
ソースコード
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])))
AEn