結果

問題 No.402 最も海から遠い場所
ユーザー convexineqconvexineq
提出日時 2021-02-13 15:13:23
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 2,664 ms / 3,000 ms
コード長 625 bytes
コンパイル時間 432 ms
コンパイル使用メモリ 87,108 KB
実行使用メモリ 452,288 KB
最終ジャッジ日時 2023-09-27 23:39:55
合計ジャッジ時間 16,187 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 95 ms
71,640 KB
testcase_01 AC 93 ms
71,736 KB
testcase_02 AC 116 ms
77,476 KB
testcase_03 AC 95 ms
71,584 KB
testcase_04 AC 97 ms
71,760 KB
testcase_05 AC 103 ms
76,784 KB
testcase_06 AC 98 ms
71,536 KB
testcase_07 AC 98 ms
71,196 KB
testcase_08 AC 95 ms
71,228 KB
testcase_09 AC 102 ms
76,736 KB
testcase_10 AC 96 ms
71,384 KB
testcase_11 AC 114 ms
77,808 KB
testcase_12 AC 109 ms
77,796 KB
testcase_13 AC 134 ms
78,080 KB
testcase_14 AC 127 ms
77,888 KB
testcase_15 AC 186 ms
86,920 KB
testcase_16 AC 209 ms
91,920 KB
testcase_17 AC 1,100 ms
259,324 KB
testcase_18 AC 2,664 ms
290,100 KB
testcase_19 AC 2,079 ms
452,288 KB
testcase_20 AC 2,060 ms
254,400 KB
testcase_21 AC 2,082 ms
415,116 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

h,w = map(int,input().split())
b = ["."*(w+2)]
for _ in range(h):
    b.append("."+input()+".")
b += ["."*(w+2)]
h += 2; w += 2
dist = [[-1]*w for _ in range(h)]
from collections import deque
q = deque()
for i in range(h):
    for j in range(w):
        if b[i][j] == ".":
            q.append((i,j))
            dist[i][j] = 0
while q:
    i,j = q.popleft()
    for di in range(-1,2):
        for dj in range(-1,2):
            ni = i+di
            nj = j+dj
            if 0 <= ni < h and 0 <= nj < w and dist[ni][nj] == -1:
                dist[ni][nj] = dist[i][j] + 1
                q.append((ni,nj))
print(dist[i][j])
0