結果

問題 No.402 最も海から遠い場所
ユーザー kohei2019kohei2019
提出日時 2022-01-21 00:03:46
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 829 bytes
コンパイル時間 147 ms
コンパイル使用メモリ 82,164 KB
実行使用メモリ 257,160 KB
最終ジャッジ日時 2024-05-03 11:04:46
合計ジャッジ時間 7,905 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
59,392 KB
testcase_01 WA -
testcase_02 AC 57 ms
65,536 KB
testcase_03 AC 40 ms
53,504 KB
testcase_04 AC 40 ms
53,632 KB
testcase_05 AC 41 ms
54,144 KB
testcase_06 AC 40 ms
53,888 KB
testcase_07 WA -
testcase_08 AC 43 ms
53,760 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 53 ms
64,384 KB
testcase_12 WA -
testcase_13 AC 84 ms
77,056 KB
testcase_14 AC 75 ms
76,540 KB
testcase_15 AC 144 ms
86,020 KB
testcase_16 AC 198 ms
90,304 KB
testcase_17 WA -
testcase_18 TLE -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import collections
import sys
input = sys.stdin.readline
def main():
    H,W = map(int,input().split())
    lsHW = ['.'*(W+2)]+['.'+input()+'.' for i in range(H)]+['.'*(W+2)]
    H += 2
    W += 2
    INF = 5000
    cost = [[INF]*(W) for i in range(H)]
    dxy = [(0,1),(1,0),(-1,0),(0,-1),(1,1),(-1,1),(1,-1),(-1,-1)]
    d = collections.deque()
    for i in range(H):
        for j in range(W):
            if lsHW[i][j] == '.':
                cost[i][j] = 0
                d.append((i,j))
    cmax = 0
    while d:
        x,y = d.popleft()
        for dx,dy in dxy:
            if 0<=x+dx<H and 0<= y+dy <W:
                if cost[x+dx][y+dy] > cost[x][y] + 1:
                    cost[x+dx][y+dy] = cost[x][y] + 1
                    cmax = cost[x][y] + 1
                    d.append((x+dx,y+dy))
    print(cmax)
main()
0