結果

問題 No.402 最も海から遠い場所
ユーザー rpy3cpprpy3cpp
提出日時 2016-07-22 23:10:50
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
MLE  
実行時間 -
コード長 1,147 bytes
コンパイル時間 128 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 516,608 KB
最終ジャッジ日時 2024-04-24 05:59:04
合計ジャッジ時間 6,654 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 31 ms
16,256 KB
testcase_01 AC 29 ms
11,008 KB
testcase_02 AC 34 ms
11,264 KB
testcase_03 AC 28 ms
10,880 KB
testcase_04 AC 27 ms
10,880 KB
testcase_05 AC 26 ms
11,008 KB
testcase_06 AC 26 ms
10,880 KB
testcase_07 AC 26 ms
10,880 KB
testcase_08 AC 25 ms
11,008 KB
testcase_09 AC 26 ms
11,008 KB
testcase_10 AC 25 ms
10,880 KB
testcase_11 AC 27 ms
11,008 KB
testcase_12 AC 26 ms
11,008 KB
testcase_13 AC 85 ms
14,464 KB
testcase_14 AC 49 ms
11,904 KB
testcase_15 AC 397 ms
34,304 KB
testcase_16 AC 598 ms
43,712 KB
testcase_17 MLE -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

def read_data():
    H, W = map(int, input().split())
    S = [input() for i in range(H)]
    return H, W, S

def solve(H, W, S):
    dist = [[-1] * W for i in range(H)]
    pool = []
    for h in range(H):
        Sh = S[h]
        disth = dist[h]
        for w in range(W):
            if Sh[w] == '.':
                disth[w] = 0
                pool.append((h, w))
    if not pool:
        return (min(H, W) + 1) // 2
    for i in range(W):
        pool.append((-1, i))
        pool.append((H, i))
    for i in range(H):
        pool.append((i, -1))
        pool.append((i, W))
    d = 0
    while pool:
        d += 1
        newpool = []
        for h, w in pool:
            for dh, dw in [(1,1), (1,0), (1,-1), (0,1),(0,-1),(-1,1),(-1,0),(-1,-1)]:
                nh = dh + h
                nw = dw + w
                if nh < 0 or nh >= H or nw < 0 or nw >= W:
                    continue
                if S[nh][nw] == '.' or dist[nh][nw] != -1:
                    continue
                dist[nh][nw] = d
                newpool.append((nh, nw))
        pool = newpool
    return d - 1

H, W, S = read_data()
print(solve(H, W, S))
0