結果

問題 No.402 最も海から遠い場所
ユーザー mitsuomitsuo
提出日時 2018-08-24 11:10:38
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,259 bytes
コンパイル時間 269 ms
コンパイル使用メモリ 87,344 KB
実行使用メモリ 119,156 KB
最終ジャッジ日時 2023-09-02 10:32:19
合計ジャッジ時間 9,031 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 RE -
testcase_07 RE -
testcase_08 WA -
testcase_09 WA -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 TLE -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque

def solve(H, W, M):
    dmap = [[-1] * H for _ in range(0, W)]
    candidates = deque([])

    for h in range(0, H):
        for w in range(0, W):
            if M[h][w] == ".":
                dmap[h][w] = 0
                candidates.append((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
                candidates.appendleft((1, h, w))

    max = 1
    count = 0
    while(len(candidates)):
        count += 1
        can = candidates.pop()
        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:
                        candidates.appendleft((d + 1, xi, yi))
    print(f"looped {count} times")
    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