結果
問題 |
No.157 2つの空洞
|
ユーザー |
![]() |
提出日時 | 2022-03-27 00:23:39 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
AC
|
実行時間 | 32 ms / 2,000 ms |
コード長 | 956 bytes |
コンパイル時間 | 119 ms |
コンパイル使用メモリ | 12,672 KB |
実行使用メモリ | 10,880 KB |
最終ジャッジ日時 | 2024-10-15 15:45:28 |
合計ジャッジ時間 | 1,329 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 16 |
ソースコード
from collections import deque W,H=map(int,input().split()) MAP=[input().strip() for i in range(H)] Q=deque() ANS=[[1<<30]*W for i in range(H)] flag=0 for i in range(H): for j in range(W): if MAP[i][j]=="." and flag==0: Q2=[(i,j)] ANS[i][j]=0 flag=1 while Q2: x,y=Q2.pop() Q.append((x,y)) for z,w in [(x+1,y),(x-1,y),(x,y+1),(x,y-1)]: if 0<=z<H and 0<=w<W and ANS[z][w]==1<<30 and MAP[z][w]==".": ANS[z][w]=0 Q2.append((z,w)) while Q: x,y=Q.popleft() for z,w in [(x+1,y),(x-1,y),(x,y+1),(x,y-1)]: if 0<=z<H and 0<=w<W and ANS[z][w]>ANS[x][y]+1: ANS[z][w]=ANS[x][y]+1 Q.append((z,w)) LANS=1<<30 for i in range(H): for j in range(W): if ANS[i][j]!=0 and MAP[i][j]==".": LANS=min(LANS,ANS[i][j]) print(LANS-1)