結果
| 問題 |
No.402 最も海から遠い場所
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2016-07-22 23:10:21 |
| 言語 | PyPy2 (7.3.15) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,181 bytes |
| コンパイル時間 | 869 ms |
| コンパイル使用メモリ | 76,816 KB |
| 実行使用メモリ | 366,616 KB |
| 最終ジャッジ日時 | 2024-11-06 13:01:56 |
| 合計ジャッジ時間 | 10,415 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 15 TLE * 1 -- * 3 |
ソースコード
input = raw_input
range = xrange
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))