結果

問題 No.402 最も海から遠い場所
コンテスト
ユーザー titia
提出日時 2023-03-20 01:40:10
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
AC  
(最新)
TLE  
(最初)
実行時間 2,010 ms / 3,000 ms
コード長 829 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 209 ms
コンパイル使用メモリ 85,120 KB
実行使用メモリ 456,704 KB
最終ジャッジ日時 2026-04-06 17:04:58
合計ジャッジ時間 9,825 ms
ジャッジサーバーID
(参考情報)
judge1_1 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 19
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

from collections import deque
import sys
input = sys.stdin.readline

H,W=map(int,input().split())
MAP=[input() for i in range(H)]

ANS=[[1<<30]*(W+2) for i in range(H+2)]

Q=deque()

for i in range(H+2):
    ANS[i][0]=0
    ANS[i][W+1]=0
    Q.append((i,0))
    Q.append((i,W+1))


for i in range(W+2):
    ANS[0][i]=0
    ANS[H+1][i]=0
    Q.append((0,i))
    Q.append((H+1,i))

for i in range(H):
    for j in range(W):
        if MAP[i][j]==".":
            Q.append((i+1,j+1))
            ANS[i+1][j+1]=0

while Q:
    x,y=Q.popleft()
    for z,w in [(x-1,y-1),(x-1,y),(x-1,y+1),(x,y-1),(x,y+1),(x+1,y-1),(x+1,y),(x+1,y+1)]:
        if 0<=z<H+2 and 0<=w<W+2 and ANS[z][w]>ANS[x][y]+1:
            ANS[z][w]=ANS[x][y]+1
            Q.append((z,w))

MAX=0
for ans in ANS:
    MAX=max(MAX,max(ans))
    #print(*ans)

print(MAX)
0