結果

問題 No.867 避難経路
ユーザー vwxyzvwxyz
提出日時 2024-04-14 17:01:33
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,017 bytes
コンパイル時間 366 ms
コンパイル使用メモリ 82,584 KB
実行使用メモリ 232,712 KB
最終ジャッジ日時 2024-04-14 17:03:36
合計ジャッジ時間 121,813 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 90 ms
76,380 KB
testcase_01 AC 97 ms
76,536 KB
testcase_02 AC 98 ms
76,408 KB
testcase_03 AC 104 ms
76,448 KB
testcase_04 AC 95 ms
76,468 KB
testcase_05 AC 89 ms
76,632 KB
testcase_06 AC 96 ms
76,672 KB
testcase_07 AC 96 ms
76,472 KB
testcase_08 AC 97 ms
76,580 KB
testcase_09 AC 122 ms
76,480 KB
testcase_10 AC 128 ms
76,464 KB
testcase_11 AC 94 ms
76,532 KB
testcase_12 AC 109 ms
76,556 KB
testcase_13 AC 93 ms
76,848 KB
testcase_14 AC 99 ms
76,692 KB
testcase_15 AC 4,504 ms
228,864 KB
testcase_16 AC 4,439 ms
227,304 KB
testcase_17 AC 4,519 ms
230,432 KB
testcase_18 AC 4,371 ms
228,332 KB
testcase_19 AC 4,382 ms
228,100 KB
testcase_20 AC 4,318 ms
225,972 KB
testcase_21 AC 4,177 ms
226,420 KB
testcase_22 AC 4,293 ms
228,080 KB
testcase_23 AC 4,441 ms
232,712 KB
testcase_24 AC 4,460 ms
228,892 KB
testcase_25 AC 4,334 ms
227,744 KB
testcase_26 AC 4,500 ms
227,752 KB
testcase_27 AC 4,400 ms
228,780 KB
testcase_28 AC 4,783 ms
227,456 KB
testcase_29 AC 4,658 ms
228,700 KB
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 AC 4,044 ms
226,164 KB
testcase_35 AC 4,210 ms
227,404 KB
testcase_36 AC 4,086 ms
226,248 KB
testcase_37 AC 3,950 ms
225,120 KB
testcase_38 AC 3,891 ms
225,472 KB
testcase_39 AC 3,896 ms
225,172 KB
testcase_40 AC 3,953 ms
226,184 KB
testcase_41 AC 62 ms
69,092 KB
testcase_42 AC 74 ms
74,412 KB
testcase_43 AC 84 ms
76,356 KB
権限があれば一括ダウンロードができます

ソースコード

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=51
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