結果

問題 No.402 最も海から遠い場所
ユーザー titiatitia
提出日時 2023-03-20 01:37:08
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 775 bytes
コンパイル時間 278 ms
コンパイル使用メモリ 81,820 KB
実行使用メモリ 451,264 KB
最終ジャッジ日時 2023-10-18 17:58:18
合計ジャッジ時間 15,128 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 44 ms
55,492 KB
testcase_01 AC 44 ms
55,492 KB
testcase_02 AC 73 ms
72,752 KB
testcase_03 AC 43 ms
55,492 KB
testcase_04 AC 43 ms
55,492 KB
testcase_05 AC 48 ms
61,516 KB
testcase_06 AC 42 ms
55,492 KB
testcase_07 AC 43 ms
55,492 KB
testcase_08 AC 42 ms
55,492 KB
testcase_09 AC 48 ms
61,516 KB
testcase_10 AC 44 ms
55,492 KB
testcase_11 AC 63 ms
68,620 KB
testcase_12 AC 58 ms
66,336 KB
testcase_13 AC 100 ms
77,420 KB
testcase_14 AC 92 ms
76,588 KB
testcase_15 AC 162 ms
85,892 KB
testcase_16 AC 195 ms
89,860 KB
testcase_17 AC 1,429 ms
257,240 KB
testcase_18 TLE -
testcase_19 AC 2,505 ms
451,264 KB
testcase_20 AC 2,764 ms
253,440 KB
testcase_21 AC 2,436 ms
414,560 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque

H,W=map(int,input().split())
MAP=[input() for i in range(H)]

ANS=[[1<<30]*(W+2) for i in range(H+2)]

Q=deque()

for i in range(H+2):
    ANS[i][0]=0
    ANS[i][W+1]=0
    Q.append((i,0))
    Q.append((i,W+1))


for i in range(W+2):
    ANS[0][i]=0
    ANS[H+1][i]=0
    Q.append((0,i))
    Q.append((H+1,i))

for i in range(H):
    for j in range(W):
        if MAP[i][j]==".":
            Q.append((i+1,j+1))
            ANS[i+1][j+1]=0

while Q:
    x,y=Q.popleft()
    for z in range(x-1,x+2):
        for w in range(y-1,y+2):
            if 0<=z<H+2 and 0<=w<W+2 and ANS[z][w]>ANS[x][y]+1:
                ANS[z][w]=ANS[x][y]+1
                Q.append((z,w))

MAX=0
for ans in ANS:
    MAX=max(MAX,max(ans))
    #print(*ans)

print(MAX)
0