結果

問題 No.402 最も海から遠い場所
ユーザー DrDrpilotDrDrpilot
提出日時 2022-06-02 16:28:37
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,084 bytes
コンパイル時間 177 ms
コンパイル使用メモリ 81,756 KB
実行使用メモリ 315,592 KB
最終ジャッジ日時 2023-10-21 01:12:06
合計ジャッジ時間 9,120 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 45 ms
59,912 KB
testcase_01 AC 48 ms
55,428 KB
testcase_02 AC 66 ms
68,448 KB
testcase_03 AC 43 ms
55,428 KB
testcase_04 AC 45 ms
55,428 KB
testcase_05 AC 46 ms
55,428 KB
testcase_06 AC 43 ms
55,428 KB
testcase_07 AC 44 ms
55,428 KB
testcase_08 AC 44 ms
55,428 KB
testcase_09 AC 44 ms
55,428 KB
testcase_10 AC 44 ms
55,428 KB
testcase_11 AC 64 ms
68,500 KB
testcase_12 AC 58 ms
66,320 KB
testcase_13 AC 93 ms
76,452 KB
testcase_14 AC 99 ms
76,356 KB
testcase_15 AC 144 ms
78,152 KB
testcase_16 AC 244 ms
84,688 KB
testcase_17 AC 1,096 ms
185,364 KB
testcase_18 TLE -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque
h,w=map(int,input().split())
g=[input() for _ in range(h)]
d=[[-1]*w for _ in range(h)]
dy=[1,1,1,0,0,-1,-1,-1]
dx=[1,0,-1,1,-1,1,0,-1]
for y in range(h):
    for x in range(w):
        if g[y][x]=='.':
            d[y][x]=0
            continue
        sea=False
        for i in range(8):
            ny=y+dy[i]
            nx=x+dx[i]
            if not (0<=ny<h and 0<=nx<w):
                sea=True
                break
            if g[ny][nx]=='.':
                sea=True
                break
        if sea:
            d[y][x]=1
q=deque()
for i in range(h):
    for j in range(w):
        if g[i][j]=='.':
            continue
        if d[i][j]==1:
            q.append((i,j))
while q:
    y,x=q.popleft()
    for i in range(8):
        ny=y+dy[i];nx=x+dx[i]
        if not(0<=ny<h and 0<=nx<w):
            continue
        if g[ny][nx]=='.':
            continue
        if d[ny][nx]==-1:
            d[ny][nx]=d[y][x]+1
            q.append((ny,nx))
ans=0
for i in range(h):
    for j in range(w):
        ans=max(ans,d[i][j])
print(ans)
0