結果

問題 No.402 最も海から遠い場所
ユーザー rlangevin
提出日時 2023-11-27 00:03:00
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 2,772 ms / 3,000 ms
コード長 880 bytes
コンパイル時間 356 ms
コンパイル使用メモリ 82,560 KB
実行使用メモリ 446,208 KB
最終ジャッジ日時 2024-09-26 11:59:42
合計ジャッジ時間 13,882 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 19
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

H, W = map(int, input().split())
dx = [1, 0, -1, 0, 1, 1, -1, -1]
dy = [0, 1, 0, -1, 1, -1, 1, -1]
from collections import *
Q = deque()
dist = [[-1] * (W + 2) for i in range(H + 2)]
            
for j in range(W + 2):
    dist[0][j] = 0
    Q.append((0, j))
    dist[H+1][j] = 0
    Q.append((H+1, j))
    
for i in range(1, H+1):
    L = ["."] + list(input().rstrip()) + ["."]
    for j in range(W + 2):
        if L[j] == ".":
            dist[i][j] = 0
            Q.append((i, j))
        
ans = 0
while Q:
    i, j = Q.popleft()
    for k in range(8):
        x = i + dx[k]
        y = j + dy[k]
        if x < 0 or x > H + 1 or y < 0 or y > W + 1:
            continue
        if dist[x][y] != -1:
            continue
        dist[x][y] = dist[i][j] + 1
        ans = max(ans, dist[x][y])
        Q.append((x, y))
        
print(ans)
0