結果

問題 No.402 最も海から遠い場所
ユーザー roarisroaris
提出日時 2019-12-12 20:51:01
言語 PyPy3
(7.3.15)
結果
MLE  
実行時間 -
コード長 913 bytes
コンパイル時間 535 ms
コンパイル使用メモリ 86,868 KB
実行使用メモリ 905,452 KB
最終ジャッジ日時 2023-09-07 21:25:27
合計ジャッジ時間 11,390 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 MLE -
testcase_01 AC 100 ms
71,680 KB
testcase_02 AC 123 ms
77,712 KB
testcase_03 AC 100 ms
71,608 KB
testcase_04 AC 99 ms
71,304 KB
testcase_05 AC 106 ms
76,596 KB
testcase_06 AC 101 ms
71,656 KB
testcase_07 AC 101 ms
71,496 KB
testcase_08 AC 100 ms
71,512 KB
testcase_09 AC 107 ms
76,620 KB
testcase_10 AC 102 ms
71,448 KB
testcase_11 AC 120 ms
77,660 KB
testcase_12 AC 118 ms
77,428 KB
testcase_13 AC 148 ms
80,284 KB
testcase_14 AC 137 ms
78,524 KB
testcase_15 AC 238 ms
99,012 KB
testcase_16 AC 325 ms
118,588 KB
testcase_17 AC 2,562 ms
472,896 KB
testcase_18 MLE -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

def bfs():
    q = deque([])
    ans = 0
    
    for i in range(H+2):
        for j in range(W+2):
            if S[i][j]=='.':
                q.append((i, j))
                S[i][j] = 0
    
    while q:
        cx, cy = q.popleft()
        
        for i in range(-1, 2):
            for j in range(-1, 2):
                if i==0 and j==0:
                    continue
                
                nx, ny = cx+i, cy+j
                
                if 0<=nx<H+2 and 0<=ny<W+2 and S[nx][ny]=='#':
                    S[nx][ny] = S[cx][cy]+1
                    q.append((nx, ny))
                    
                    if ans<S[nx][ny]:
                        ans = S[nx][ny]
    
    return ans

H, W = map(int, input().split())
S = [list('.'*(W+2))]+[list('.'+input()[:-1]+'.') for _ in range(H)]+[list('.'*(W+2))]

print(bfs())
0