結果

問題 No.867 避難経路
ユーザー nep_pudding3nep_pudding3
提出日時 2019-08-16 23:13:01
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 1,354 bytes
コンパイル時間 255 ms
コンパイル使用メモリ 12,152 KB
実行使用メモリ 96,132 KB
最終ジャッジ日時 2023-10-24 04:44:15
合計ジャッジ時間 11,489 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 30 ms
10,360 KB
testcase_01 AC 31 ms
10,360 KB
testcase_02 AC 31 ms
10,360 KB
testcase_03 AC 30 ms
10,356 KB
testcase_04 AC 30 ms
10,360 KB
testcase_05 AC 30 ms
10,360 KB
testcase_06 AC 30 ms
10,360 KB
testcase_07 AC 31 ms
10,360 KB
testcase_08 AC 31 ms
10,356 KB
testcase_09 AC 30 ms
10,364 KB
testcase_10 AC 35 ms
10,360 KB
testcase_11 AC 30 ms
10,360 KB
testcase_12 AC 30 ms
10,364 KB
testcase_13 AC 31 ms
10,364 KB
testcase_14 AC 30 ms
10,360 KB
testcase_15 TLE -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque
H,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)
0