結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 47 ms
59,520 KB
testcase_01 AC 46 ms
53,888 KB
testcase_02 AC 166 ms
78,228 KB
testcase_03 AC 44 ms
53,248 KB
testcase_04 AC 46 ms
53,504 KB
testcase_05 AC 53 ms
60,160 KB
testcase_06 AC 44 ms
53,120 KB
testcase_07 AC 45 ms
53,120 KB
testcase_08 AC 45 ms
53,248 KB
testcase_09 AC 51 ms
59,904 KB
testcase_10 AC 47 ms
53,888 KB
testcase_11 AC 139 ms
78,152 KB
testcase_12 AC 98 ms
76,672 KB
testcase_13 AC 308 ms
82,992 KB
testcase_14 AC 221 ms
79,836 KB
testcase_15 AC 809 ms
102,124 KB
testcase_16 AC 1,412 ms
125,780 KB
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 >= width:
                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