結果

問題 No.402 最も海から遠い場所
ユーザー brthyyjpbrthyyjp
提出日時 2021-09-24 07:05:35
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 2,676 ms / 3,000 ms
コード長 835 bytes
コンパイル時間 480 ms
コンパイル使用メモリ 87,004 KB
実行使用メモリ 380,336 KB
最終ジャッジ日時 2023-09-18 20:09:28
合計ジャッジ時間 15,106 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 94 ms
71,580 KB
testcase_01 AC 94 ms
71,564 KB
testcase_02 AC 127 ms
78,172 KB
testcase_03 AC 94 ms
71,564 KB
testcase_04 AC 95 ms
71,636 KB
testcase_05 AC 101 ms
76,660 KB
testcase_06 AC 95 ms
71,836 KB
testcase_07 AC 95 ms
71,852 KB
testcase_08 AC 93 ms
71,524 KB
testcase_09 AC 100 ms
76,972 KB
testcase_10 AC 96 ms
71,688 KB
testcase_11 AC 121 ms
77,820 KB
testcase_12 AC 120 ms
77,788 KB
testcase_13 AC 147 ms
79,184 KB
testcase_14 AC 134 ms
78,072 KB
testcase_15 AC 199 ms
85,640 KB
testcase_16 AC 226 ms
89,088 KB
testcase_17 AC 1,195 ms
231,052 KB
testcase_18 AC 2,676 ms
271,296 KB
testcase_19 AC 2,010 ms
380,336 KB
testcase_20 AC 2,179 ms
256,800 KB
testcase_21 AC 2,274 ms
349,460 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
import io, os
input = sys.stdin.readline

h, w = map(int, input().split())
S = [str(input().rstrip()) for i in range(h)]
S = ['.'*(w+2)]+['.'+s+'.' for s in S]+['.'*(w+2)]
from collections import deque
INF = 10**18
q = deque([])
dist = [INF]*((h+2)*(w+2))
for y in range(h+2):
    for x in range(w+2):
        if S[y][x] == '.':
            dist[y*(w+2)+x] = 0
            q.append(y*(w+2)+x)
while q:
    v = q.popleft()
    y, x = divmod(v, w+2)
    for dy in range(-1, 2):
        for dx in range(-1, 2):
            if dy == 0 and dx == 0:
                continue
            ny, nx = y+dy, x+dx
            if 0 <= ny < h+2 and 0 <= nx < w+2:
                if dist[ny*(w+2)+nx] > dist[y*(w+2)+x]+1:
                    q.append(ny*(w+2)+nx)
                    dist[ny*(w+2)+nx] = dist[y*(w+2)+x]+1
print(max(dist))
0