結果

問題 No.402 最も海から遠い場所
ユーザー 👑 rin204rin204
提出日時 2022-02-02 15:55:49
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 2,444 ms / 3,000 ms
コード長 785 bytes
コンパイル時間 1,052 ms
コンパイル使用メモリ 87,160 KB
実行使用メモリ 452,560 KB
最終ジャッジ日時 2023-09-02 02:50:12
合計ジャッジ時間 14,782 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 83 ms
71,756 KB
testcase_01 AC 83 ms
71,788 KB
testcase_02 AC 131 ms
77,980 KB
testcase_03 AC 84 ms
71,808 KB
testcase_04 AC 84 ms
71,576 KB
testcase_05 AC 82 ms
71,568 KB
testcase_06 AC 81 ms
71,704 KB
testcase_07 AC 81 ms
71,832 KB
testcase_08 AC 84 ms
71,728 KB
testcase_09 AC 83 ms
71,420 KB
testcase_10 AC 85 ms
71,664 KB
testcase_11 AC 103 ms
77,636 KB
testcase_12 AC 96 ms
77,296 KB
testcase_13 AC 117 ms
77,816 KB
testcase_14 AC 111 ms
77,788 KB
testcase_15 AC 156 ms
87,104 KB
testcase_16 AC 182 ms
90,488 KB
testcase_17 AC 1,049 ms
258,648 KB
testcase_18 AC 2,444 ms
292,196 KB
testcase_19 AC 2,011 ms
452,560 KB
testcase_20 AC 1,926 ms
254,352 KB
testcase_21 AC 1,866 ms
415,396 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque

h, w = map(int, input().split())
S = ["." * (w + 2)] + ["." + input() + "." for _ in range(h)] + ["." * (w + 2)]
h += 2
w += 2
queue = deque()
dist = [[-1] * w for _ in range(h)]
for i in range(h):
    for j in range(w):
        if S[i][j] == ".":
            dist[i][j] = 0
            queue.append((i, j))

ans = 0
while queue:
    i, j = queue.popleft()
    for di in range(-1, 2):
        ni = i + di
        if ni == -1 or ni == h:
            continue
        for dj in range(-1, 2):
            nj = j + dj
            if nj == -1 or nj == w:
                continue
            if dist[ni][nj] != -1:
                continue
            dist[ni][nj] = dist[i][j] + 1
            ans = dist[ni][nj]
            queue.append((ni, nj))

print(ans)
0