結果
問題 | No.867 避難経路 |
ユーザー |
|
提出日時 | 2022-05-21 12:26:32 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,130 bytes |
コンパイル時間 | 273 ms |
コンパイル使用メモリ | 81,920 KB |
実行使用メモリ | 353,964 KB |
最終ジャッジ日時 | 2024-09-20 11:28:53 |
合計ジャッジ時間 | 14,865 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | -- * 3 |
other | AC * 15 TLE * 1 -- * 25 |
ソースコード
import sys input = sys.stdin.readline from heapq import heappush,heappop h,w = map(int,input().split()) gx,gy = [int(x)-1 for x in input().split()] A = [list(map(int,input().split())) for i in range(h)] inf = 10**20 dp = [[[inf]*(500) for i in range(w)] for j in range(h)] dist = [[inf]*w for i in range(h)] dist[gx][gy] = A[gx][gy] dp[gx][gy][0] = A[gx][gy] H = [] heappush(H,[0,A[gx][gy],gx,gy]) while H: d,c,x,y = heappop(H) if dp[x][y][d] != c: continue # print(d,c,x,y) for dx,dy in ((1,0),(0,1),(0,-1),(-1,0)): nx = x+dx ny = y+dy if 0 <= nx < h and 0 <= ny < w: nc = c + A[nx][ny] if dist[nx][ny] <= nc: continue if d < 499 and dp[nx][ny][d+1] > nc: dp[nx][ny][d+1] = nc dist[nx][ny] = nc heappush(H,[d+1,nc,nx,ny]) q = int(input()) for _ in range(q): x,y,k = map(int,input().split()) x -= 1 y -= 1 ans = inf k = k**2 nc = k # print(dp[x][y][:15]) for i in range(500): ans = min(ans,dp[x][y][i]+nc) nc += k print(ans)