結果
問題 | No.867 避難経路 |
ユーザー |
![]() |
提出日時 | 2019-08-16 23:13:38 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 2,410 ms / 6,000 ms |
コード長 | 1,354 bytes |
コンパイル時間 | 669 ms |
コンパイル使用メモリ | 82,304 KB |
実行使用メモリ | 209,380 KB |
最終ジャッジ日時 | 2024-09-22 22:05:46 |
合計ジャッジ時間 | 49,581 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 41 |
ソースコード
from collections import dequeH,W = map(int,input().split())gx,gy = map(int,input().split())A = list(list(map(int,input().split()))for i in range(H))cost = [[[[0,float('inf')]]for i in range(W)]for j in range(H)]cost[gx-1][gy-1][-1] = [1,A[gx-1][gy-1]]queue = deque([[gy-1,gx-1]])while queue != deque([]):qx,qy = queue.popleft()if qx < W-1 and cost[qy][qx+1][-1][1] > cost[qy][qx][-1][1] + A[qy][qx+1]:cost[qy][qx+1].append([cost[qy][qx][-1][0]+1,cost[qy][qx][-1][1] + A[qy][qx+1]])queue.append([qx+1,qy])if qx > 0 and cost[qy][qx-1][-1][1] > cost[qy][qx][-1][1] + A[qy][qx-1]:cost[qy][qx-1].append([cost[qy][qx][-1][0]+1,cost[qy][qx][-1][1] + A[qy][qx-1]])queue.append([qx-1,qy])if qy > 0 and cost[qy-1][qx][-1][1] > cost[qy][qx][-1][1] + A[qy-1][qx]:cost[qy-1][qx].append([cost[qy][qx][-1][0]+1,cost[qy][qx][-1][1] + A[qy-1][qx]])queue.append([qx,qy-1])if qy < H-1 and cost[qy+1][qx][-1][1] > cost[qy][qx][-1][1] + A[qy+1][qx]:cost[qy+1][qx].append([cost[qy][qx][-1][0]+1,cost[qy][qx][-1][1] + A[qy+1][qx]])queue.append([qx,qy+1])Q = int(input())ans = []for i in range(Q):x,y,k = map(int,input().split())hoge = float('inf')for a,b in cost[x-1][y-1]:hoge = min(a*k**2+b,hoge)ans.append(hoge)for i in ans:print(i)