結果

問題 No.157 2つの空洞
ユーザー ssmkzkssmkzk
提出日時 2019-02-19 17:19:03
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 30 ms / 2,000 ms
コード長 893 bytes
コンパイル時間 258 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 11,008 KB
最終ジャッジ日時 2024-04-20 14:24:27
合計ジャッジ時間 1,316 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 27 ms
10,880 KB
testcase_01 AC 27 ms
11,008 KB
testcase_02 AC 28 ms
11,008 KB
testcase_03 AC 29 ms
10,880 KB
testcase_04 AC 29 ms
11,008 KB
testcase_05 AC 28 ms
11,008 KB
testcase_06 AC 27 ms
10,880 KB
testcase_07 AC 27 ms
11,008 KB
testcase_08 AC 28 ms
11,008 KB
testcase_09 AC 27 ms
11,008 KB
testcase_10 AC 26 ms
10,880 KB
testcase_11 AC 25 ms
10,880 KB
testcase_12 AC 25 ms
11,008 KB
testcase_13 AC 26 ms
10,880 KB
testcase_14 AC 26 ms
11,008 KB
testcase_15 AC 27 ms
11,008 KB
testcase_16 AC 30 ms
11,008 KB
testcase_17 AC 27 ms
11,008 KB
testcase_18 AC 25 ms
10,880 KB
testcase_19 AC 26 ms
10,880 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# import numpy as np

W, H = map(int, input().split())
l = []
for i in range(H):
    ll = list(input())
    l.append(ll)
flg = 0
for i in range(H):
    for j in range(W):
        if l[i][j] == ".":
            flg = 1
            first_h = i
            first_w = j
            break
    if flg:
        break

l_ikko = []

def search_hole(t, y):
	if l[t][y] == ".":
		l[t][y] = 1
		l_ikko.append([t, y])
		if t - 1 >= 0:
			search_hole(t - 1, y)
		if t + 1 <= H:
			search_hole(t + 1, y)
		if y - 1 >= 0:
			search_hole(t, y - 1)
		if y + 1 <= W:
			search_hole(t, y + 1)

     
search_hole(first_h, first_w)
l_niko = []

d_min = 100

for i in range(H):
	for j in range(W):
		if l[i][j] == ".":
			l_niko.append([i, j])

for i in range(len(l_ikko)):
	for j in range(len(l_niko)):
		d_min = min(d_min, abs(l_ikko[i][0] - l_niko[j][0]) + abs(l_ikko[i][1] - l_niko[j][1]))




print(d_min -1)


0