結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
55,492 KB
testcase_01 AC 40 ms
55,492 KB
testcase_02 AC 62 ms
66,512 KB
testcase_03 AC 41 ms
55,492 KB
testcase_04 AC 40 ms
55,492 KB
testcase_05 AC 41 ms
55,492 KB
testcase_06 AC 40 ms
55,492 KB
testcase_07 AC 41 ms
55,492 KB
testcase_08 AC 41 ms
55,492 KB
testcase_09 AC 41 ms
55,492 KB
testcase_10 AC 41 ms
55,492 KB
testcase_11 AC 52 ms
64,440 KB
testcase_12 AC 50 ms
64,200 KB
testcase_13 AC 81 ms
77,120 KB
testcase_14 AC 74 ms
76,308 KB
testcase_15 AC 147 ms
85,660 KB
testcase_16 AC 181 ms
89,768 KB
testcase_17 AC 1,496 ms
256,868 KB
testcase_18 TLE -
testcase_19 TLE -
testcase_20 TLE -
testcase_21 AC 2,905 ms
414,240 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque
import sys
input = sys.stdin.readline

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,w in [(x-1,y-1),(x-1,y),(x-1,y+1),(x,y-1),(x,y+1),(x+1,y-1),(x+1,y),(x+1,y+1)]:
        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