結果

問題 No.157 2つの空洞
ユーザー yomo3yomo3
提出日時 2020-03-12 00:44:37
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 818 bytes
コンパイル時間 148 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 203,936 KB
最終ジャッジ日時 2024-04-27 22:05:27
合計ジャッジ時間 4,384 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

from collections import deque

W, H = map(int, input().split())
C = [list(input()) for _ in range(H)]

routes = []
for h in range(H-1):
    for w in range(W-1):
        if C[h][w] == '.':
            r = []
            q = deque()
            q.append((h, w))
            while q:
                y0, x0 = q.popleft()
                C[y0][x0] = '*' #done
                r.append((y0, x0))
                for dy, dx in ((-1, 0), (0, 1), (1, 0), (0, -1)):
                    y1, x1 = y0 + dy, x0 + dx
                    if 0 <= y1 < H and 0 <= x1 < W and C[y1][x1] == '.':
                        q.append((y1, x1))
            routes.append(r)

ans = H * W
for p0 in routes[0]:
    for p1 in routes[1]:
        d = abs(p0[0] - p1[0]) + abs(p0[1] - p1[1])
        if d - 1 < ans:
            ans = d - 1

print(ans)
0