結果

問題 No.402 最も海から遠い場所
ユーザー tktk_snsntktk_snsn
提出日時 2020-12-13 01:34:52
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 2,395 ms / 3,000 ms
コード長 844 bytes
コンパイル時間 240 ms
コンパイル使用メモリ 81,836 KB
実行使用メモリ 379,284 KB
最終ジャッジ日時 2023-10-20 02:54:29
合計ジャッジ時間 13,074 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 44 ms
55,620 KB
testcase_01 AC 39 ms
55,620 KB
testcase_02 AC 59 ms
68,668 KB
testcase_03 AC 41 ms
55,620 KB
testcase_04 AC 39 ms
55,620 KB
testcase_05 AC 42 ms
55,620 KB
testcase_06 AC 40 ms
55,620 KB
testcase_07 AC 39 ms
55,620 KB
testcase_08 AC 41 ms
55,620 KB
testcase_09 AC 40 ms
55,620 KB
testcase_10 AC 41 ms
55,620 KB
testcase_11 AC 58 ms
66,604 KB
testcase_12 AC 48 ms
62,180 KB
testcase_13 AC 87 ms
77,100 KB
testcase_14 AC 75 ms
74,448 KB
testcase_15 AC 138 ms
84,332 KB
testcase_16 AC 155 ms
86,524 KB
testcase_17 AC 973 ms
222,484 KB
testcase_18 AC 2,395 ms
275,884 KB
testcase_19 AC 1,736 ms
379,284 KB
testcase_20 AC 1,863 ms
243,568 KB
testcase_21 AC 1,789 ms
356,140 KB
権限があれば一括ダウンロードができます

ソースコード

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 = 10 ** 4


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

que = deque()
for i in range(H):
    for j in range(W):
        if G[i][j] == ".":
            que.appendleft(i * R + j)
            dist[i][j] = 0
        elif i == 0 or i == H - 1 or j == 0 or j == W - 1:
            que.append(i * R + j)
            dist[i][j] = 1

while que:
    x, y = divmod(que.popleft(), R)
    now = dist[x][y]
    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
            que.append(nx * R + ny)

print(now)
0