結果
| 問題 |
No.2913 二次元距離空間
|
| コンテスト | |
| ユーザー |
👑 |
| 提出日時 | 2024-06-15 14:02:49 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 823 ms / 2,000 ms |
| コード長 | 493 bytes |
| コンパイル時間 | 342 ms |
| コンパイル使用メモリ | 81,792 KB |
| 実行使用メモリ | 191,216 KB |
| 最終ジャッジ日時 | 2024-06-15 16:25:06 |
| 合計ジャッジ時間 | 8,544 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 28 |
ソースコード
R,I,O=range,input,print
H,W=map(int,I().split())
S=[I()for i in R(H)]
V=H*W
E=[]
for v in R(V):
i,j,e=v//W,v%W,[]
if i and S[i-1][j]>'#':e+=[[v-W,1]]
if i+1<H and S[i+1][j]>'#':e+=[[v+W,1]]
if j and S[i][j-1]>'#':e+=[[v-1,V]]
if j+1<W and S[i][j+1]>'#':e+=[[v+1,V]]
E+=[e]
import heapq
A=[V*V]*V
A[0]=0
Q=[[0,0]]
while len(Q):
w,i=heapq.heappop(Q)
if w>A[i]:continue
for[j,v]in E[i]:
if w+v<A[j]:A[j]=w+v;heapq.heappush(Q,[w+v,j])
w=A[V-1]
if w<V*V:O("Yes");O(w//V,w%V)
else:O("No")