結果
問題 |
No.1283 Extra Fee
|
ユーザー |
|
提出日時 | 2023-02-01 22:56:02 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
|
実行時間 | - |
コード長 | 956 bytes |
コンパイル時間 | 177 ms |
コンパイル使用メモリ | 82,048 KB |
実行使用メモリ | 121,384 KB |
最終ジャッジ日時 | 2024-07-01 15:51:16 |
合計ジャッジ時間 | 23,111 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 29 TLE * 1 |
ソースコード
import heapq INF = 1 << 60 n, m = map(int, input().split()) cost = [[0 for _ in range(n)] for _ in range(n)] for _ in range(m): hi, wi, ci = map(int, input().split()) cost[hi - 1][wi - 1] = ci dx = [1, 0, -1, 0] dy = [0, 1, 0, -1] dist = [[[INF for _ in range(2)] for _ in range(n)] for _ in range(n)] dist[0][0][0] = 0 hp = [(0, 0, 0, 0)] while len(hp) > 0: cd, ci, cx, cy = heapq.heappop(hp) if cd > dist[cx][cy][ci]: continue for d in range(4): nx = cx + dx[d] if nx < 0 or nx >= n: continue ny = cy + dy[d] if ny < 0 or ny >= n: continue if dist[nx][ny][ci] > dist[cx][cy][ci] + cost[nx][ny] + 1: dist[nx][ny][ci] = dist[cx][cy][ci] + cost[nx][ny] + 1 heapq.heappush(hp, (dist[nx][ny][ci], ci, nx, ny)) if ci == 0 and dist[nx][ny][1] > dist[cx][cy][ci] + 1: dist[nx][ny][1] = dist[cx][cy][ci] + 1 heapq.heappush(hp, (dist[nx][ny][1], 1, nx, ny)) print(min(dist[-1][-1]))