結果

問題 No.402 最も海から遠い場所
ユーザー nebukuro09nebukuro09
提出日時 2016-09-23 10:54:46
言語 PyPy2
(7.3.15)
結果
TLE  
実行時間 -
コード長 801 bytes
コンパイル時間 1,860 ms
コンパイル使用メモリ 76,416 KB
実行使用メモリ 380,184 KB
最終ジャッジ日時 2024-04-28 21:26:09
合計ジャッジ時間 9,669 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 97 ms
81,024 KB
testcase_01 AC 97 ms
75,392 KB
testcase_02 AC 121 ms
78,336 KB
testcase_03 AC 90 ms
75,264 KB
testcase_04 AC 88 ms
75,776 KB
testcase_05 AC 95 ms
75,392 KB
testcase_06 AC 87 ms
75,264 KB
testcase_07 AC 90 ms
75,776 KB
testcase_08 AC 89 ms
75,648 KB
testcase_09 AC 89 ms
75,264 KB
testcase_10 AC 88 ms
75,648 KB
testcase_11 AC 105 ms
78,080 KB
testcase_12 AC 100 ms
78,208 KB
testcase_13 AC 162 ms
86,144 KB
testcase_14 AC 128 ms
79,872 KB
testcase_15 AC 433 ms
116,632 KB
testcase_16 AC 674 ms
138,912 KB
testcase_17 TLE -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

H, W = map(int, raw_input().split())
board = ['.'*(W+2)]
for i in xrange(H):
    board.append('.'+raw_input()+'.')
board.append('.'*(W+2))

frontier = set()
visited = set()
for i in xrange(H+2):
    for j in xrange(W+2):
        if board[i][j] == '.':
            frontier.add((i, j))


dr = [-1, -1, -1, 0, 0, 1, 1, 1]
dc = [-1, 0, 1, -1, 1, -1, 0, 1]
ans = 0
while len(visited) < (H+2)*(W+2):
    ans += 1
    new_frontier = set()
    for r, c in frontier:
        for i in xrange(8):
            nr, nc = r+dr[i], c+dc[i]
            if nr < 0 or nr >= H+2 or nc < 0 or nc >=W+2:
                continue
            if (nr, nc) in visited or (nr, nc) in frontier:
                continue
            new_frontier.add((nr, nc))
    visited |= frontier
    frontier = set(new_frontier)
print ans-1
0