結果

問題 No.402 最も海から遠い場所
ユーザー tktk_snsn
提出日時 2020-12-13 01:44:36
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 994 bytes
コンパイル時間 142 ms
コンパイル使用メモリ 82,164 KB
実行使用メモリ 679,952 KB
最終ジャッジ日時 2024-09-19 22:41:18
合計ジャッジ時間 16,282 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 15 WA * 1 TLE * 2 MLE * 1
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
DX = (-1, 0, 1, 0, -1, -1, 1, 1)
DY = (0, 1, 0, -1, -1, 1, -1, 1)
R = 1500


H, W = map(int, input().split())
G = [input().rstrip() for _ in range(H)]
dist = [[R]*W for _ in range(H)]

X = deque()
Y = deque()
D = deque()
for i in range(H):
    for j in range(W):
        if G[i][j] == ".":
            dist[i][j] = 0
            X.appendleft(i)
            Y.appendleft(j)
            D.appendleft(0)
        elif i == 0 or i == H - 1 or j == 0 or j == W - 1:
            dist[i][j] = 1
            X.append(i)
            Y.append(j)
            D.append(1)

while X:
    x = X.popleft()
    y = Y.popleft()
    now = D.popleft()
    for dx, dy in zip(DX, DY):
        nx = x + dx
        ny = y + dy
        if 0 <= nx < H and 0 <= ny < W and dist[nx][ny] > now + 1:
            dist[nx][ny] = now + 1
            X.append(nx)
            Y.append(ny)
            D.append(now + 1)

print(now)
0