結果
| 問題 |
No.402 最も海から遠い場所
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2019-12-12 20:42:56 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 942 bytes |
| コンパイル時間 | 215 ms |
| コンパイル使用メモリ | 82,348 KB |
| 実行使用メモリ | 273,968 KB |
| 最終ジャッジ日時 | 2024-06-25 14:53:29 |
| 合計ジャッジ時間 | 9,545 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 15 TLE * 1 -- * 3 |
ソースコード
import sys
input = sys.stdin.readline
from collections import deque
def bfs():
q = deque([])
dist = [[-1]*(W+2) for _ in range(H+2)]
for i in range(H+2):
for j in range(W+2):
if S[i][j]=='.':
q.append((i, j))
dist[i][j] = 0
while q:
cx, cy = q.popleft()
for i in range(-1, 2):
for j in range(-1, 2):
if i==0 and j==0:
continue
nx, ny = cx+i, cy+j
if 0<=nx<H+2 and 0<=ny<W+2 and dist[nx][ny]==-1:
dist[nx][ny] = dist[cx][cy]+1
q.append((nx, ny))
return dist
H, W = map(int, input().split())
S = ['.'*(W+2)]+['.'+input()[:-1]+'.' for _ in range(H)]+['.'*(W+2)]
dist = bfs()
ans = 0
for i in range(H+2):
for j in range(W+2):
ans = max(ans, dist[i][j])
print(ans)