結果
| 問題 |
No.402 最も海から遠い場所
|
| ユーザー |
はむ吉🐹
|
| 提出日時 | 2016-07-26 13:36:54 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,482 bytes |
| コンパイル時間 | 180 ms |
| コンパイル使用メモリ | 82,152 KB |
| 実行使用メモリ | 394,216 KB |
| 最終ジャッジ日時 | 2024-11-06 16:57:23 |
| 合計ジャッジ時間 | 7,084 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 5 WA * 4 RE * 5 TLE * 1 -- * 4 |
ソースコード
#!/usr/bin/env pypy3
import array
import heapq
import itertools
INF = 10 ** 8
def compute(height, width, is_sea):
dist = [array.array("L", (INF for _ in range(width)))
for _ in range(height)]
pq = []
for r, c in itertools.product(range(height), range(width)):
if is_sea[r][c]:
dist[r][c] = 0
pq.append((0, (r, c)))
heapq.heapify(pq)
while pq:
_, (r0, c0) = heapq.heappop(pq)
for dr, dc in itertools.product((1, 0, -1), repeat=2):
if dr == dc == 0:
continue
r, c = r0 + dr, c0 + dc
if r < 0 or r >= height or c < 0 or c >= height:
continue
if is_sea[r][c]:
continue
new_length = dist[r0][c0] + 1
if new_length < dist[r][c]:
dist[r][c] = new_length
heapq.heappush(pq, (new_length, (r, c)))
rc = itertools.product(range(height), range(width))
return max(dist[r][c] for r, c in rc)
def main():
height, width = map(int, input().split())
is_sea = [array.array("B", (True for _ in range(width + 2)))]
for _ in range(height):
row = array.array("B", (True, ))
row.extend(map(lambda x: x == ".", input()))
row.append(True)
is_sea.append(row)
is_sea.append(array.array("B", (True for _ in range(width + 2))))
print(compute(height + 2, width + 2, is_sea))
if __name__ == '__main__':
main()
はむ吉🐹