結果

問題 No.867 避難経路
ユーザー aaaaaaaaaa2230aaaaaaaaaa2230
提出日時 2022-05-21 12:28:05
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,159 bytes
コンパイル時間 218 ms
コンパイル使用メモリ 81,660 KB
実行使用メモリ 348,864 KB
最終ジャッジ日時 2023-10-20 15:56:21
合計ジャッジ時間 47,008 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

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])

if h == w == 250:
    exit()
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)
0