結果

問題 No.867 避難経路
ユーザー nep_pudding3nep_pudding3
提出日時 2019-08-16 23:13:38
言語 PyPy3
(7.3.13)
結果
AC  
実行時間 2,577 ms / 6,000 ms
コード長 1,354 bytes
コンパイル時間 1,830 ms
コンパイル使用メモリ 81,528 KB
実行使用メモリ 207,468 KB
最終ジャッジ日時 2023-10-24 05:11:30
合計ジャッジ時間 52,177 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 44 ms
55,496 KB
testcase_01 AC 45 ms
55,496 KB
testcase_02 AC 44 ms
55,496 KB
testcase_03 AC 43 ms
55,496 KB
testcase_04 AC 44 ms
55,496 KB
testcase_05 AC 44 ms
55,496 KB
testcase_06 AC 44 ms
55,496 KB
testcase_07 AC 43 ms
55,496 KB
testcase_08 AC 44 ms
55,496 KB
testcase_09 AC 44 ms
55,496 KB
testcase_10 AC 45 ms
55,496 KB
testcase_11 AC 45 ms
55,496 KB
testcase_12 AC 45 ms
55,496 KB
testcase_13 AC 46 ms
55,496 KB
testcase_14 AC 45 ms
55,496 KB
testcase_15 AC 1,715 ms
171,876 KB
testcase_16 AC 2,577 ms
202,108 KB
testcase_17 AC 1,783 ms
170,056 KB
testcase_18 AC 2,032 ms
194,924 KB
testcase_19 AC 2,079 ms
199,132 KB
testcase_20 AC 2,144 ms
190,964 KB
testcase_21 AC 2,401 ms
207,468 KB
testcase_22 AC 2,160 ms
194,412 KB
testcase_23 AC 1,860 ms
171,356 KB
testcase_24 AC 2,389 ms
201,256 KB
testcase_25 AC 2,213 ms
196,504 KB
testcase_26 AC 2,385 ms
201,304 KB
testcase_27 AC 1,957 ms
178,520 KB
testcase_28 AC 989 ms
126,072 KB
testcase_29 AC 983 ms
126,616 KB
testcase_30 AC 686 ms
133,420 KB
testcase_31 AC 785 ms
136,104 KB
testcase_32 AC 779 ms
135,544 KB
testcase_33 AC 786 ms
135,116 KB
testcase_34 AC 711 ms
132,544 KB
testcase_35 AC 1,633 ms
192,728 KB
testcase_36 AC 844 ms
131,280 KB
testcase_37 AC 1,326 ms
172,056 KB
testcase_38 AC 1,187 ms
164,656 KB
testcase_39 AC 1,070 ms
157,524 KB
testcase_40 AC 938 ms
149,832 KB
testcase_41 AC 43 ms
55,504 KB
testcase_42 AC 44 ms
55,504 KB
testcase_43 AC 43 ms
55,504 KB
権限があれば一括ダウンロードができます

ソースコード

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