結果

問題 No.402 最も海から遠い場所
ユーザー roaris
提出日時 2019-12-12 20:51:01
言語 PyPy3
(7.3.15)
結果
MLE  
実行時間 -
コード長 913 bytes
コンパイル時間 169 ms
コンパイル使用メモリ 81,816 KB
実行使用メモリ 829,624 KB
最終ジャッジ日時 2024-06-25 15:02:58
合計ジャッジ時間 10,345 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 15 MLE * 1 -- * 3
権限があれば一括ダウンロードができます

ソースコード

diff #

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

def bfs():
    q = deque([])
    ans = 0
    
    for i in range(H+2):
        for j in range(W+2):
            if S[i][j]=='.':
                q.append((i, j))
                S[i][j] = 0
    
    while q:
        cx, cy = q.popleft()
        
        for i in range(-1, 2):
            for j in range(-1, 2):
                if i==0 and j==0:
                    continue
                
                nx, ny = cx+i, cy+j
                
                if 0<=nx<H+2 and 0<=ny<W+2 and S[nx][ny]=='#':
                    S[nx][ny] = S[cx][cy]+1
                    q.append((nx, ny))
                    
                    if ans<S[nx][ny]:
                        ans = S[nx][ny]
    
    return ans

H, W = map(int, input().split())
S = [list('.'*(W+2))]+[list('.'+input()[:-1]+'.') for _ in range(H)]+[list('.'*(W+2))]

print(bfs())
0