結果

問題 No.402 最も海から遠い場所
ユーザー mitsuomitsuo
提出日時 2018-08-24 10:56:01
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 1,196 bytes
コンパイル時間 318 ms
コンパイル使用メモリ 11,132 KB
実行使用メモリ 14,816 KB
最終ジャッジ日時 2023-09-02 10:09:28
合計ジャッジ時間 6,757 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
12,640 KB
testcase_01 AC 16 ms
8,204 KB
testcase_02 AC 38 ms
8,712 KB
testcase_03 WA -
testcase_04 AC 17 ms
8,104 KB
testcase_05 AC 17 ms
8,068 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 16 ms
8,148 KB
testcase_09 AC 17 ms
8,140 KB
testcase_10 AC 16 ms
8,120 KB
testcase_11 AC 36 ms
8,116 KB
testcase_12 AC 21 ms
8,140 KB
testcase_13 TLE -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import heapq

def solve(H, W, M):
    dmap = []
    candidates = []

    for h in range(0, H):
        dmap.append([-1] * W)
        for w in range(0, W):
            if M[h][w] == ".":
                dmap[h][w] = 0
                heapq.heappush(candidates, (0, h, w))
            elif (h == 0 or h == H - 1 or w == 0 or w == W - 1) and M[h][w] == "#":
                dmap[h][w] = 1
                heapq.heappush(candidates, (1, h, w))

    max = 0
    while(len(candidates)):
        can = heapq.heappop(candidates)
        d = can[0]
        h = can[1]
        w = can[2]

        for (xi, yi) in [(h-1, w-1),(h-1, w), (h-1, w+1),
                     (h , w - 1), (h, w + 1),
                     (h + 1, w - 1), (h + 1, w), (h + 1, w + 1)]:
            if xi > 0 and yi > 0 and xi < H and yi < W:
                if dmap[xi][yi] == -1:
                    dmap[xi][yi] = d + 1
                    max = d + 1
                    if (d + 1, xi, yi) not in candidates:
                        heapq.heappush(candidates, (d + 1, xi, yi))
    return max

if __name__ == "__main__":
    H, W = tuple([int(c) for c in input().split(" ")])
    print(solve(H, W, [input() for _ in range(0, H)]))
0