結果

問題 No.402 最も海から遠い場所
ユーザー tktk_snsntktk_snsn
提出日時 2020-12-13 01:44:36
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 994 bytes
コンパイル時間 162 ms
コンパイル使用メモリ 81,816 KB
実行使用メモリ 679,532 KB
最終ジャッジ日時 2023-10-20 02:55:08
合計ジャッジ時間 11,371 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
55,500 KB
testcase_01 AC 40 ms
55,500 KB
testcase_02 AC 60 ms
68,516 KB
testcase_03 AC 39 ms
55,500 KB
testcase_04 AC 41 ms
55,500 KB
testcase_05 AC 42 ms
55,500 KB
testcase_06 AC 40 ms
55,500 KB
testcase_07 AC 40 ms
55,500 KB
testcase_08 AC 39 ms
55,500 KB
testcase_09 AC 40 ms
55,500 KB
testcase_10 AC 40 ms
55,500 KB
testcase_11 AC 58 ms
66,440 KB
testcase_12 AC 48 ms
62,008 KB
testcase_13 AC 99 ms
78,096 KB
testcase_14 AC 85 ms
76,896 KB
testcase_15 AC 164 ms
93,412 KB
testcase_16 AC 198 ms
102,416 KB
testcase_17 AC 1,581 ms
376,564 KB
testcase_18 TLE -
testcase_19 MLE -
testcase_20 WA -
testcase_21 MLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
DX = (-1, 0, 1, 0, -1, -1, 1, 1)
DY = (0, 1, 0, -1, -1, 1, -1, 1)
R = 1500


H, W = map(int, input().split())
G = [input().rstrip() for _ in range(H)]
dist = [[R]*W for _ in range(H)]

X = deque()
Y = deque()
D = deque()
for i in range(H):
    for j in range(W):
        if G[i][j] == ".":
            dist[i][j] = 0
            X.appendleft(i)
            Y.appendleft(j)
            D.appendleft(0)
        elif i == 0 or i == H - 1 or j == 0 or j == W - 1:
            dist[i][j] = 1
            X.append(i)
            Y.append(j)
            D.append(1)

while X:
    x = X.popleft()
    y = Y.popleft()
    now = D.popleft()
    for dx, dy in zip(DX, DY):
        nx = x + dx
        ny = y + dy
        if 0 <= nx < H and 0 <= ny < W and dist[nx][ny] > now + 1:
            dist[nx][ny] = now + 1
            X.append(nx)
            Y.append(ny)
            D.append(now + 1)

print(now)
0