結果

問題 No.402 最も海から遠い場所
ユーザー rlangevinrlangevin
提出日時 2023-11-27 00:03:00
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 2,672 ms / 3,000 ms
コード長 880 bytes
コンパイル時間 203 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 445,880 KB
最終ジャッジ日時 2023-11-27 00:03:15
合計ジャッジ時間 12,929 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
55,608 KB
testcase_01 AC 40 ms
55,608 KB
testcase_02 AC 54 ms
66,544 KB
testcase_03 AC 37 ms
55,608 KB
testcase_04 AC 37 ms
55,608 KB
testcase_05 AC 38 ms
55,608 KB
testcase_06 AC 38 ms
55,604 KB
testcase_07 AC 37 ms
55,608 KB
testcase_08 AC 37 ms
55,608 KB
testcase_09 AC 37 ms
55,608 KB
testcase_10 AC 37 ms
55,608 KB
testcase_11 AC 50 ms
64,452 KB
testcase_12 AC 48 ms
64,444 KB
testcase_13 AC 72 ms
76,920 KB
testcase_14 AC 61 ms
70,636 KB
testcase_15 AC 119 ms
83,500 KB
testcase_16 AC 148 ms
84,760 KB
testcase_17 AC 1,110 ms
255,544 KB
testcase_18 AC 2,672 ms
312,500 KB
testcase_19 AC 2,007 ms
445,880 KB
testcase_20 AC 1,999 ms
240,056 KB
testcase_21 AC 2,216 ms
398,008 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

H, 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] = 0
    Q.append((0, j))
    dist[H+1][j] = 0
    Q.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] = 0
            Q.append((i, j))
        
ans = 0
while 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:
            continue
        if dist[x][y] != -1:
            continue
        dist[x][y] = dist[i][j] + 1
        ans = max(ans, dist[x][y])
        Q.append((x, y))
        
print(ans)
0