結果
問題 | No.402 最も海から遠い場所 |
ユーザー |
![]() |
提出日時 | 2023-11-27 00:03:00 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 2,772 ms / 3,000 ms |
コード長 | 880 bytes |
コンパイル時間 | 356 ms |
コンパイル使用メモリ | 82,560 KB |
実行使用メモリ | 446,208 KB |
最終ジャッジ日時 | 2024-09-26 11:59:42 |
合計ジャッジ時間 | 13,882 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 19 |
ソースコード
import sysinput = sys.stdin.readlineH, W = map(int, input().split())dx = [1, 0, -1, 0, 1, 1, -1, -1]dy = [0, 1, 0, -1, 1, -1, 1, -1]from collections import *Q = deque()dist = [[-1] * (W + 2) for i in range(H + 2)]for j in range(W + 2):dist[0][j] = 0Q.append((0, j))dist[H+1][j] = 0Q.append((H+1, j))for i in range(1, H+1):L = ["."] + list(input().rstrip()) + ["."]for j in range(W + 2):if L[j] == ".":dist[i][j] = 0Q.append((i, j))ans = 0while Q:i, j = Q.popleft()for k in range(8):x = i + dx[k]y = j + dy[k]if x < 0 or x > H + 1 or y < 0 or y > W + 1:continueif dist[x][y] != -1:continuedist[x][y] = dist[i][j] + 1ans = max(ans, dist[x][y])Q.append((x, y))print(ans)