結果

問題 No.157 2つの空洞
ユーザー matsu7874matsu7874
提出日時 2015-12-20 11:09:15
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 897 bytes
コンパイル時間 129 ms
コンパイル使用メモリ 11,944 KB
実行使用メモリ 15,012 KB
最終ジャッジ日時 2023-10-17 14:08:49
合計ジャッジ時間 8,918 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 35 ms
14,388 KB
testcase_01 AC 36 ms
10,040 KB
testcase_02 AC 56 ms
10,044 KB
testcase_03 AC 97 ms
10,056 KB
testcase_04 AC 186 ms
10,068 KB
testcase_05 AC 361 ms
10,056 KB
testcase_06 AC 1,392 ms
10,164 KB
testcase_07 AC 81 ms
10,056 KB
testcase_08 AC 68 ms
10,044 KB
testcase_09 AC 355 ms
10,056 KB
testcase_10 AC 95 ms
10,056 KB
testcase_11 TLE -
testcase_12 TLE -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

W, H = map(int, input().split())
maze = [input() for i in range(H)]
dist = [[W * H for j in range(W * H)] for j in range(W * H)]

for i in range(W * H):
    dist[i][i] = 0
    for d in (-W, -1, 1, W):
        if i + d < 0 or W * H <= i + d:
            continue
        if d in (-1, 1) and (i + d) // W != i // W:
            continue
        if maze[(i + d) // W][(i + d) % W] == '#':
            dist[i][i + d] = 1
        else:
            dist[i][i + d] = 0

for k in range(W * H):
    for i in range(W * H):
        for j in range(W * H):
            dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j])

min_cost = W * H
for i in range(W+1, W*H):
    if maze[i // W][i % W] == '#':
        continue
    for j in range(i + 1, W * (H-1)):
        if maze[j // W][j % W] == '#':
            continue
        if dist[i][j] > 0:
            min_cost = min(min_cost, dist[i][j])

print(min_cost)
0