結果

問題 No.867 避難経路
ユーザー vwxyzvwxyz
提出日時 2024-04-14 16:59:38
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,017 bytes
コンパイル時間 422 ms
コンパイル使用メモリ 82,376 KB
実行使用メモリ 232,088 KB
最終ジャッジ日時 2024-04-14 17:01:59
合計ジャッジ時間 119,358 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 90 ms
76,468 KB
testcase_01 AC 98 ms
76,556 KB
testcase_02 AC 99 ms
76,696 KB
testcase_03 AC 105 ms
76,532 KB
testcase_04 AC 94 ms
76,492 KB
testcase_05 AC 90 ms
76,352 KB
testcase_06 AC 99 ms
76,576 KB
testcase_07 AC 97 ms
76,520 KB
testcase_08 AC 99 ms
76,888 KB
testcase_09 AC 99 ms
76,420 KB
testcase_10 AC 132 ms
76,588 KB
testcase_11 AC 114 ms
76,508 KB
testcase_12 AC 111 ms
76,648 KB
testcase_13 AC 96 ms
76,416 KB
testcase_14 AC 99 ms
76,512 KB
testcase_15 AC 4,491 ms
228,244 KB
testcase_16 AC 4,543 ms
226,700 KB
testcase_17 AC 4,650 ms
229,976 KB
testcase_18 AC 4,554 ms
227,364 KB
testcase_19 AC 4,431 ms
227,360 KB
testcase_20 AC 4,247 ms
225,296 KB
testcase_21 AC 4,097 ms
225,364 KB
testcase_22 AC 4,051 ms
227,796 KB
testcase_23 AC 4,253 ms
232,088 KB
testcase_24 AC 4,174 ms
228,100 KB
testcase_25 AC 4,198 ms
227,128 KB
testcase_26 AC 4,438 ms
227,256 KB
testcase_27 AC 4,490 ms
228,076 KB
testcase_28 AC 4,494 ms
226,736 KB
testcase_29 AC 4,466 ms
228,272 KB
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 AC 4,191 ms
225,824 KB
testcase_35 AC 4,161 ms
226,876 KB
testcase_36 AC 4,007 ms
225,932 KB
testcase_37 AC 3,982 ms
224,288 KB
testcase_38 AC 3,837 ms
224,512 KB
testcase_39 AC 3,715 ms
224,724 KB
testcase_40 AC 3,741 ms
225,396 KB
testcase_41 AC 62 ms
69,128 KB
testcase_42 AC 75 ms
74,624 KB
testcase_43 AC 88 ms
76,404 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=50
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