結果

問題 No.157 2つの空洞
ユーザー convexineqconvexineq
提出日時 2020-12-09 01:24:56
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 50 ms / 2,000 ms
コード長 756 bytes
コンパイル時間 212 ms
コンパイル使用メモリ 81,580 KB
実行使用メモリ 61,856 KB
最終ジャッジ日時 2023-10-19 02:52:13
合計ジャッジ時間 2,084 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 44 ms
55,464 KB
testcase_01 AC 46 ms
55,464 KB
testcase_02 AC 43 ms
55,464 KB
testcase_03 AC 45 ms
55,464 KB
testcase_04 AC 45 ms
55,464 KB
testcase_05 AC 44 ms
55,464 KB
testcase_06 AC 45 ms
55,464 KB
testcase_07 AC 42 ms
55,464 KB
testcase_08 AC 45 ms
55,464 KB
testcase_09 AC 44 ms
55,464 KB
testcase_10 AC 43 ms
55,464 KB
testcase_11 AC 44 ms
55,464 KB
testcase_12 AC 44 ms
55,464 KB
testcase_13 AC 48 ms
61,520 KB
testcase_14 AC 49 ms
61,520 KB
testcase_15 AC 50 ms
61,596 KB
testcase_16 AC 49 ms
61,856 KB
testcase_17 AC 49 ms
61,596 KB
testcase_18 AC 49 ms
61,596 KB
testcase_19 AC 50 ms
61,856 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

w,h = map(int,input().split())
b = [input() for _ in range(h)]

for i in range(h):
    for j in range(w):
        if b[i][j] == ".":
            si,sj = i,j

from collections import deque
INF = 999
dist = [[INF]*w for _ in range(h)]
dist[si][sj] = 0
q = deque([(si,sj)])

while q:
    vi,vj = q.popleft()
    for ni,nj in [(vi+1,vj),(vi,vj+1),(vi-1,vj),(vi,vj-1)]:
        if 0 <= ni < h and 0 < nj < w and dist[ni][nj] == INF:
            if b[ni][nj] == "#":
                dist[ni][nj] = dist[vi][vj] + 1
                q.append((ni,nj))
            else:
                dist[ni][nj] = dist[vi][vj]
                q.appendleft((ni,nj))
ans = 0
for i in range(h):
    for j in range(w):
        if b[i][j] == ".": ans = max(ans,dist[i][j])
print(ans)
0