結果

問題 No.402 最も海から遠い場所
ユーザー はむ吉🐹はむ吉🐹
提出日時 2016-07-26 13:36:54
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,482 bytes
コンパイル時間 174 ms
コンパイル使用メモリ 82,432 KB
実行使用メモリ 383,428 KB
最終ジャッジ日時 2024-04-24 09:32:27
合計ジャッジ時間 6,934 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 50 ms
59,136 KB
testcase_01 AC 43 ms
53,888 KB
testcase_02 AC 161 ms
78,108 KB
testcase_03 AC 41 ms
52,864 KB
testcase_04 AC 42 ms
53,632 KB
testcase_05 AC 50 ms
60,288 KB
testcase_06 WA -
testcase_07 RE -
testcase_08 AC 41 ms
52,992 KB
testcase_09 AC 48 ms
59,776 KB
testcase_10 RE -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 TLE -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#!/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()
0