結果

問題 No.867 避難経路
ユーザー aaaaaaaaaa2230aaaaaaaaaa2230
提出日時 2022-05-21 13:25:05
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,772 bytes
コンパイル時間 279 ms
コンパイル使用メモリ 81,856 KB
実行使用メモリ 376,636 KB
最終ジャッジ日時 2023-10-20 16:08:23
合計ジャッジ時間 87,146 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
54,144 KB
testcase_01 AC 41 ms
54,108 KB
testcase_02 AC 41 ms
54,084 KB
testcase_03 AC 44 ms
54,100 KB
testcase_04 AC 40 ms
54,080 KB
testcase_05 AC 46 ms
54,148 KB
testcase_06 AC 41 ms
54,064 KB
testcase_07 AC 41 ms
54,056 KB
testcase_08 AC 41 ms
54,060 KB
testcase_09 AC 45 ms
59,984 KB
testcase_10 AC 42 ms
54,096 KB
testcase_11 AC 41 ms
54,048 KB
testcase_12 AC 42 ms
54,096 KB
testcase_13 AC 41 ms
54,048 KB
testcase_14 AC 41 ms
54,028 KB
testcase_15 AC 5,019 ms
356,592 KB
testcase_16 AC 5,844 ms
364,372 KB
testcase_17 AC 4,474 ms
352,952 KB
testcase_18 TLE -
testcase_19 TLE -
testcase_20 AC 5,693 ms
368,216 KB
testcase_21 TLE -
testcase_22 AC 3,934 ms
351,984 KB
testcase_23 AC 3,068 ms
346,856 KB
testcase_24 AC 3,917 ms
354,876 KB
testcase_25 AC 1,988 ms
348,836 KB
testcase_26 AC 2,051 ms
348,932 KB
testcase_27 AC 1,632 ms
345,384 KB
testcase_28 AC 1,374 ms
338,936 KB
testcase_29 AC 1,363 ms
338,884 KB
testcase_30 AC 1,129 ms
339,276 KB
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 AC 1,107 ms
337,848 KB
testcase_35 AC 1,099 ms
336,996 KB
testcase_36 AC 1,087 ms
332,996 KB
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 AC 39 ms
53,580 KB
testcase_42 AC 39 ms
53,580 KB
testcase_43 AC 40 ms
53,580 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline
from heapq import heappush,heappop

# def divmod(x,mod):
    
#     a = x//mod
#     return a,x-a*mod
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)]
step = [[inf]*w for i in range(h)]
upd = [[-1]*w for i in range(h)]
first = [[-1]*w for i in range(h)]
dist[gx][gy] = A[gx][gy]
dp[gx][gy][0] = A[gx][gy]
step[gx][gy] = 0
H = [[gx,gy]]
dx = [1,0,-1,0]
dy = [0,1,0,-1]
mod2 = 1<<16

for d in range(500):
    nH = []

    for x,y in H:
        c = dp[x][y][d]
        if dp[x][y][d] != c:
            continue
        if first[x][y] == -1:
            first[x][y] = [c,d+1]
        # print(d,c,x,y)
        for i in range(4):
            nx = x+dx[i]
            ny = y+dy[i]
            if nx < 0 or nx >= h or ny < 0 or ny >= w:
                continue
            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
                step[nx][ny] = d+1
                if upd[nx][ny] != d+1:
                    upd[nx][ny] = d+1
                    nH.append([nx,ny])
    if nH:
        H = nH
    else:
        break


q = int(input())
for _ in range(q):
    x,y,k = map(int,input().split())
    x -= 1
    y -= 1

    if k >= 222:
        ans,d = first[x][y]
        ans += d*k**2
        print(ans)
        continue
    ans = inf
    k = k**2
    nc = k
    ndp = dp[x][y]

    for i in range(step[x][y]+1):
        if ans > ndp[i]+nc:
            ans = ndp[i]+nc
        nc += k

    print(ans)
0