結果
| 問題 | 
                            No.402 最も海から遠い場所
                             | 
                    
| コンテスト | |
| ユーザー | 
                             | 
                    
| 提出日時 | 2018-08-24 11:20:53 | 
| 言語 | Python3  (3.13.1 + numpy 2.2.1 + scipy 1.14.1)  | 
                    
| 結果 | 
                             
                                RE
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 1,378 bytes | 
| コンパイル時間 | 191 ms | 
| コンパイル使用メモリ | 12,800 KB | 
| 実行使用メモリ | 239,972 KB | 
| 最終ジャッジ日時 | 2024-06-11 17:27:33 | 
| 合計ジャッジ時間 | 6,231 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge5 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 5 RE * 10 TLE * 1 -- * 3 | 
ソースコード
from collections import deque
def solve(H, W, M):
    dmap = [[-1] * H for _ in range(0, W)]
    candidates = deque([])
    checked = set()
    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))
                checked.add((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))
                checked.add((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 (xi, yi) in checked:
                    continue
                checked.add((xi, yi))
                
                if dmap[xi][yi] == -1:
                    dmap[xi][yi] = d + 1
                    max = d + 1
                    candidates.appendleft((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)]))