結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 44 ms
55,492 KB
testcase_01 AC 42 ms
55,492 KB
testcase_02 AC 64 ms
70,588 KB
testcase_03 AC 43 ms
55,492 KB
testcase_04 AC 42 ms
55,492 KB
testcase_05 AC 46 ms
61,528 KB
testcase_06 AC 42 ms
55,492 KB
testcase_07 AC 42 ms
55,492 KB
testcase_08 AC 42 ms
55,492 KB
testcase_09 AC 46 ms
61,528 KB
testcase_10 AC 43 ms
55,492 KB
testcase_11 AC 58 ms
66,456 KB
testcase_12 AC 55 ms
64,216 KB
testcase_13 AC 90 ms
77,132 KB
testcase_14 AC 79 ms
76,428 KB
testcase_15 AC 153 ms
85,772 KB
testcase_16 AC 189 ms
90,100 KB
testcase_17 AC 1,575 ms
256,924 KB
testcase_18 TLE -
testcase_19 AC 2,804 ms
451,228 KB
testcase_20 TLE -
testcase_21 AC 2,786 ms
415,880 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 in [x-1,x,x+1]:
        for w in [y-1,y,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