結果

問題 No.402 最も海から遠い場所
ユーザー kohei2019kohei2019
提出日時 2022-01-21 00:05:31
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 836 bytes
コンパイル時間 618 ms
コンパイル使用メモリ 87,080 KB
実行使用メモリ 453,084 KB
最終ジャッジ日時 2023-08-16 01:18:06
合計ジャッジ時間 9,436 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 81 ms
71,620 KB
testcase_01 AC 86 ms
71,624 KB
testcase_02 AC 105 ms
77,088 KB
testcase_03 AC 90 ms
71,808 KB
testcase_04 AC 88 ms
71,740 KB
testcase_05 AC 84 ms
71,460 KB
testcase_06 AC 85 ms
71,620 KB
testcase_07 AC 84 ms
71,644 KB
testcase_08 AC 83 ms
71,684 KB
testcase_09 AC 80 ms
71,624 KB
testcase_10 AC 85 ms
71,724 KB
testcase_11 AC 93 ms
77,532 KB
testcase_12 AC 96 ms
77,180 KB
testcase_13 AC 117 ms
78,096 KB
testcase_14 AC 106 ms
77,600 KB
testcase_15 AC 171 ms
86,764 KB
testcase_16 AC 211 ms
91,180 KB
testcase_17 AC 1,334 ms
258,496 KB
testcase_18 TLE -
testcase_19 AC 2,690 ms
453,084 KB
testcase_20 TLE -
testcase_21 AC 2,738 ms
415,632 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import collections
import sys
input = sys.stdin.readline
def main():
    H,W = map(int,input().split())
    lsHW = ['.'*(W+2)]+['.'+input()[:-1]+'.' 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