結果

問題 No.867 避難経路
ユーザー vwxyzvwxyz
提出日時 2024-04-14 16:59:03
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,018 bytes
コンパイル時間 222 ms
コンパイル使用メモリ 82,376 KB
実行使用メモリ 249,288 KB
最終ジャッジ日時 2024-04-14 16:59:18
合計ジャッジ時間 14,133 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 100 ms
76,700 KB
testcase_01 AC 109 ms
76,696 KB
testcase_02 AC 110 ms
76,416 KB
testcase_03 AC 113 ms
76,392 KB
testcase_04 AC 110 ms
76,416 KB
testcase_05 AC 103 ms
76,532 KB
testcase_06 AC 104 ms
76,428 KB
testcase_07 AC 109 ms
76,440 KB
testcase_08 AC 108 ms
76,560 KB
testcase_09 AC 106 ms
76,672 KB
testcase_10 AC 112 ms
76,424 KB
testcase_11 AC 104 ms
76,528 KB
testcase_12 AC 121 ms
76,800 KB
testcase_13 AC 106 ms
76,404 KB
testcase_14 AC 110 ms
76,832 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 #

import heapq

H,W=map(int,input().split())
gx,gy=map(int,input().split())
gx-=1;gy-=1
A=[list(map(int,input().split())) for h in range(H)]
Q=int(input())
K=100
query=[[] for k in range(K+1)]
for q in range(Q):
    x,y,k=map(int,input().split())
    x-=1;y-=1
    query[min(k,K)].append((x,y,k,q))
ans_lst=[None]*Q
for k in range(K+1):
    w=k**2 if k<K else 1<<30
    inf=1<<60
    dist=[[inf]*W for h in range(H)]
    dist[gx][gy]=0
    queue=[(dist[gx][gy],gx,gy)]
    while queue:
        d,x,y=heapq.heappop(queue)
        for dx,dy in ((0,1),(1,0),(0,-1),(-1,0)):
            if 0<=x+dx<H and 0<=y+dy<W:
                xx,yy=x+dx,y+dy
                dd=d+w+A[xx][yy]
                if dist[xx][yy]>dd:
                    dist[xx][yy]=dd
                    heapq.heappush(queue,(dd,xx,yy))
    for x,y,c,q in query[k]:
        if k<K:
            ans_lst[q]=dist[x][y]+c**2+A[gx][gy]
        else:
            cnt,d=divmod(dist[x][y],w)
            ans_lst[q]=(cnt+1)*c**2+d+A[gx][gy]
print(*ans_lst,sep="\n")
0