結果

問題 No.402 最も海から遠い場所
ユーザー brthyyjp
提出日時 2021-09-24 07:05:35
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 2,508 ms / 3,000 ms
コード長 835 bytes
コンパイル時間 169 ms
コンパイル使用メモリ 82,176 KB
実行使用メモリ 380,544 KB
最終ジャッジ日時 2024-07-05 09:39:22
合計ジャッジ時間 12,713 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 19
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
import io, os
input = sys.stdin.readline

h, w = map(int, input().split())
S = [str(input().rstrip()) for i in range(h)]
S = ['.'*(w+2)]+['.'+s+'.' for s in S]+['.'*(w+2)]
from collections import deque
INF = 10**18
q = deque([])
dist = [INF]*((h+2)*(w+2))
for y in range(h+2):
    for x in range(w+2):
        if S[y][x] == '.':
            dist[y*(w+2)+x] = 0
            q.append(y*(w+2)+x)
while q:
    v = q.popleft()
    y, x = divmod(v, w+2)
    for dy in range(-1, 2):
        for dx in range(-1, 2):
            if dy == 0 and dx == 0:
                continue
            ny, nx = y+dy, x+dx
            if 0 <= ny < h+2 and 0 <= nx < w+2:
                if dist[ny*(w+2)+nx] > dist[y*(w+2)+x]+1:
                    q.append(ny*(w+2)+nx)
                    dist[ny*(w+2)+nx] = dist[y*(w+2)+x]+1
print(max(dist))
0