結果

問題 No.157 2つの空洞
ユーザー Konton7Konton7
提出日時 2019-05-19 22:22:25
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 46 ms / 2,000 ms
コード長 1,151 bytes
コンパイル時間 184 ms
コンパイル使用メモリ 11,992 KB
実行使用メモリ 10,252 KB
最終ジャッジ日時 2023-10-17 08:00:14
合計ジャッジ時間 1,948 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

w, h = [ int(v) for v in input().split() ]

cave = [ list(input()) for i in range(h) ]
path_list = []

for i in range(h):
    for j in range(w):
        if cave[i][j] == ".":
            path_list.append((i,j))
            


def search():
    global path_list
    outlist = [path_list[0]]
    que = [path_list[0]]

    while que != []:
        y, x = que[0][0], que[0][1]
        if (y, x+1) in path_list and (y, x+1) not in outlist:
            outlist.append((y, x+1))
            que.append((y, x+1))
        if (y, x-1) in path_list and (y, x-1) not in outlist:
            outlist.append((y, x-1))
            que.append((y, x-1))
        if (y+1, x) in path_list and (y+1, x) not in outlist:
            outlist.append((y+1, x))
            que.append((y+1, x))
        if (y-1, x) in path_list and (y-1, x) not in outlist:
            outlist.append((y-1, x))
            que.append((y-1, x))
        del que[0]

    return outlist

path1 = sorted(search())
path2 = sorted([ i for i in path_list if i not in path1 ])

d = w*h

for i in path1:
    for j in path2:
        dij = abs(i[0]-j[0]) + abs(i[1]-j[1])

        d = min(dij,d)
print(d-1)
0