結果
| 問題 |
No.1283 Extra Fee
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2022-03-15 13:08:30 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,019 bytes |
| コンパイル時間 | 247 ms |
| コンパイル使用メモリ | 82,016 KB |
| 実行使用メモリ | 136,520 KB |
| 最終ジャッジ日時 | 2024-09-22 04:58:10 |
| 合計ジャッジ時間 | 24,651 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 29 TLE * 1 |
ソースコード
import heapq
n,m=map(int,input().split())
money=[[0]*n for _ in range(n)]
for _ in range(m):
h,w,c=map(int,input().split())
money[h-1][w-1]=c
inf=float('inf')
d=[[[inf]*2 for _ in range(n)] for _ in range(n)]
d[0][0][0]=0
q=[(0,0,0,0)]
while q:
now_d,y,x,use=heapq.heappop(q)
if d[y][x][use]<now_d:
continue
for dy,dx in [(1,0),(0,1),(-1,0),(0,-1)]:
ny=y+dy;nx=x+dx
if 0<=ny<n and 0<=nx<n:
if money[ny][nx]==0:
if d[ny][nx][use]>now_d+1:
d[ny][nx][use]=now_d+1
heapq.heappush(q,(now_d+1,ny,nx,use))
else:
cost=money[ny][nx]
if d[ny][nx][use]>now_d+cost+1:
d[ny][nx][use]=now_d+cost+1
heapq.heappush(q,(now_d+cost+1,ny,nx,use))
if use==0:
if d[ny][nx][1]>now_d+1:
d[ny][nx][1]=now_d+1
heapq.heappush(q,(now_d+1,ny,nx,1))
print(d[-1][-1][1])