Problem:


Score : 300 points

Problem Statement

You are given a grid of squares with H horizontal rows and W vertical columns, where each square is painted white or black.
HW characters from A_{11} to A_{HW} represent the colors of the squares.
A_{ij} is # if the square at the i-th row from the top and the j-th column from the left is black, and A_{ij} is . if that square is white.

We will repeatedly perform the following operation until all the squares are black:

Every white square that shares a side with a black square, becomes black.

Find the number of operations that will be performed.
The initial grid has at least one black square.

Constraints

1 \leq H,W \leq 1000

A_{ij} is # or ..

The given grid has at least one black square.

Input

Input is given from Standard Input in the following format:

H W
A_{11}A_{12}...A_{1W}
:
A_{H1}A_{H2}...A_{HW}

Output

Print the number of operations that will be performed.

Sample Input 1

3 3
...
.#.
...

Sample Output 1

2

After one operation, all but the corners of the grid will be black. After one more operation, all the squares will be black.

Sample Input 2

6 6
..#..#
......
#..#..
......
.#....
....#.

Sample Output 2

3



Sample input:
3 3
...
.#.
...


Sample output:
2

Submission status: Wrong Answer

Solution code:
r, c = map(int, input().split())

cc = [input() for i in range(r)]

from collections import deque


# 縦がｙ 横がx　だから座標はy,xて書く
st=[]
for i in range(r):
    for j in range(c):
        if cc[i][j]=="#":
            st.append([i,j])

# 保留スタックtodoにスタートの位置情報を入れる
todo=deque(st)
# 検知済みリストseenを-1で初期化 (何も検知してないてこと)
seen=[[-1 for i in range(c)] for j in range(r)]

# seenにはどんだけの手数でそこに到達できるかを入れる
# 例えばスタート地点は手数0でいけるから0を入れる
for i in range(len(st)):
    seen[st[i][0]][st[i][1]]=0

# 4方向の移動リスト これ使って移動していく
ido=[[1,0],[0,1],[-1,0],[0,-1]]

# 保留リストtodoが空になるまでやる
while todo:
    y, x=todo.popleft() # 現在地は保留からの先頭とりだす
    for i in range(4): # 現在地から4方向を見る
        ny, nx=y+ido[i][0], x+ido[i][1] # 現在地から隣の座標
        # 隣の座標が区画をはみ出さないかつ、検知してないときに
        if 0<=ny<r and 0<=nx<c and seen[ny][nx]==-1 and cc[ny][nx]!="#":
            # 隣に行けるということなので検知してその手数を格納
            seen[ny][nx]=seen[y][x]+1 # 手数＝前の地点の手数+1
            todo.append([ny,nx]) # 保留リストにも入れとく

print(max(seen))

Submission status: Wrong Answer

Solution code:
h, w = map(int, input().split())
m = [['#'] * (w+2)]
for j in range(h):
    m.append(['#'])
    m[j+1].extend([i for i in input()]) #スペース区切りならinput().split()
    m[j+1].append('#')
m.append(['#'] * (w+2))

todo = []
for i in range(1, h+1):
    for j in range(1, w+1):
        if m[i][j] == '#':
            todo.append([i, j])
            m[i][j] = 0
dx = [0, 0, -1, 1]
dy = [1, -1, 0, 0]

while(todo != []):
    a = todo.pop(0) #First Out
    print(a)
    for i in range(4):
        if m[a[0]+dx[i]][a[1]+dy[i]] == '.':
            todo.append([a[0]+dx[i], a[1]+dy[i]])
            m[a[0]+dx[i]][a[1]+dy[i]] = m[a[0]][a[1]] + 1

ans = 0
for i in range(1, h+1):
    for j in range(1, w+1):
        ans = max(ans, m[i][j])

print(ans)

Submission status: Wrong Answer

Solution code:
from collections import deque
def mbfs(S,H,W,d):
    dx=[1,0,-1,0]
    dy=[0,1,0,-1]
    while(len(d)!=0):
        print(d[0])
        h=d[0][0]
        w=d[0][1]
        x=d[0][2]
        d.popleft()
        for di in range(4):
            nh=h+dx[di]
            nw=w+dy[di]
            if(nh>H-1 or nh<0 or nw>W-1 or nw<0):
                continue
            if(S[nh][nw]=='#'):
                continue
            S[nh][nw]='#'
            d.append([nh,nw,x+1])
    return x
H,W=map(int,input().split())
A=[list(input()) for i in range(H)]
d=deque()
for i in range(H):
    for j in range(W):
        if(A[i][j]=='#'):
            d.append([i,j,0])
print(mbfs(A,H,W,d))

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10 ** 7)

H, W = map(int, input().split())
A = []
for _ in range(H):
    A.append(input())

from collections import deque
todo = deque()
seen = [[False] * W for _ in range(H)]
route= [[0] * W for _ in range(H)]
for y in range(H):
    for x in range(W):
        if A[y][x] == '#':
            todo.append((x, y))
            seen[y][x] = True


seen = [[False] * W for _ in range(H)]
route= [[0] * W for _ in range(H)]

dx = [1, 0, -1, 0]
dy = [0, 1, 0, -1]
cnt = 0
while todo:
    for _ in range(len(todo)):
        x, y = todo.popleft()
        #print(x, y)
        for i in range(4):
            if 0 <= x + dx[i] < W and 0 <= y + dy[i] < H:
                if seen[y + dy[i]][x + dx[i]] == False:
                    route[y + dy[i]][x + dx[i]] = route[y][x] + 1
                    seen[y + dy[i]][x + dx[i]] = True
                    todo.append((x + dx[i], y + dy[i]))
    cnt += 1

#print(seen)
#print(route)
print(cnt - 1)
# M = 0
# for y in range(W):
#     for x in range(H):
#         M = max(M, route[y][x])
# print(M)

Submission status: Wrong Answer

Solution code:

import numpy as np
h,w = list(map(int,input().split()))
S = [[x for x in input()] for _ in range(h)]

s = np.zeros((h,w), dtype='int')
for i in range(h):
  for j in range(w):
    if S[i][j] == '.':
      s[i,j] = 1

def rev():
  for i in range(1,h)[::-1]:
    s[i,:] = np.minimum(s[i,:], s[i-1,:])
  for i in range(h-1):
    s[i,:] = np.minimum(s[i,:], s[i+1,:])
  for i in range(1,w)[::-1]:
    s[:,i] = np.minimum(s[:,i], s[:,i-1])
  for i in range(w-1):
    s[:,i] = np.minimum(s[:,i], s[:,i+1])

cnt = 1
while np.max(s) > 0:
  rev()
  cnt += 1


print(cnt)

Submission status: Wrong Answer

Solution code:

import numpy as np
h,w = list(map(int,input().split()))
S = [[x for x in input()] for _ in range(h)]

s = np.zeros((h,w), dtype='int')
for i in range(h):
  for j in range(w):
    if S[i][j] == '.':
      s[i,j] = 1

def rev():
  for i in range(1,h)[::-1]:
    s[i,:] = np.minimum(s[i,:], s[i-1,:])
  for i in range(h-1):
    s[i,:] = np.minimum(s[i,:], s[i+1,:])
  for i in range(1,w)[::-1]:
    s[:,i] = np.minimum(s[:,i], s[:,i-1])
  for i in range(w-1):
    s[:,i] = np.minimum(s[:,i], s[:,i+1])

cnt = 1
while sum( [sum(x) for x in s] ) > 0:
  rev()
  cnt += 1


print(cnt)

Submission status: Wrong Answer

Solution code:

import numpy as np
h,w = list(map(int,input().split()))
S = [[x for x in input()] for _ in range(h)]

s = np.zeros((h,w), dtype='int')
for i in range(h):
  for j in range(w):
    if S[i][j] == '.':
      s[i,j] = 1

def rev():
  for i in range(1,h)[::-1]:
    s[i,:] = np.minimum(s[i,:], s[i-1,:])
  for i in range(h-1):
    s[i,:] = np.minimum(s[i,:], s[i+1,:])
  for i in range(1,w)[::-1]:
    s[:,i] = np.minimum(s[:,i], s[:,i-1])
  for i in range(w-1):
    s[:,i] = np.minimum(s[:,i], s[:,i+1])

cnt = 0
while sum( [sum(x) for x in s] ) > 0:
  rev()
  cnt += 1


print(cnt)

Submission status: Wrong Answer

Solution code:
from collections import deque
import numpy as np
h,w = list(map(int,input().split()))
s = [[x for x in input()] for _ in range(h)]

for i in range(h):
  for j in range(w):
    if s[i][j] == '#':
      s[i][j] = 0
    if s[i][j] == '.':
      s[i][j] = 1
s = np.array(s)

def rev():
  for i in range(1,h)[::-1]:
    s[i,:] = np.minimum(s[i,:], s[i-1,:])
  for i in range(h-1):
    s[i,:] = np.minimum(s[i,:], s[i+1,:])
  for i in range(1,w)[::-1]:
    s[:,i] = np.minimum(s[:,i], s[:,i-1])
  for i in range(w-1):
    s[:,i] = np.minimum(s[:,i], s[:,i+1])

cnt = 0
while sum( [sum(x) for x in s] ) > 0:
  rev()
  cnt += 1


print(cnt)

Submission status: Wrong Answer

Solution code:
from collections import deque

Height, Width = map(int, input().split())
Map = [input() for _ in range(Height)]
min_step_map = [[10**6]*Width for _ in range(Height)]

# Find the minimum number of steps from all blacks.
# The maximum number of the obtained minimum steps is the answer.
def search_min_step(y_start, x_start):
    compare_step_map = [[0]*Width for _ in range(Height)]
    compare_step_map[y_start][x_start] = 0

    research_point = deque()
    research_point.append([y_start, x_start])
    while len(research_point) > 0:
        y_now, x_now = research_point.popleft()
        
        for dy, dx in [(-1,0), (0,-1), (1,0), (0,1)]:
            y_next, x_next = y_now+dy, x_now+dx
            if (y_next <= -1 or Height <= y_next) or \
                                              (x_next <= -1 or Width <= x_next):
                continue

            compare_step_map[y_next][x_next] = compare_step_map[y_now][x_now]+1
            if min_step_map[y_next][x_next] <= compare_step_map[y_next][x_next]:
                continue
            else:
                min_step_map[y_next][x_next] = compare_step_map[y_next][x_next]
                research_point.append([y_next, x_next])

for y in range(Height):
    for x in range(Width):
        if Map[y][x] == '#':
            search_min_step(y, x)

max_step = 0
for y in range(Height):
    max_step = max(max_step, max(min_step_map[y]))

print(max_step)

Submission status: Wrong Answer

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

h, w = map(int, readline().split())
a = [input() for i in range(h)]
s = []
for i in range(h):
    for j in range(w):
        if a[i][j] == '#':
            s.append([i, j])
test = [(0, 1), (0, -1), (1, 0), (-1, 0)]
inf = float('inf')
dist = [[inf] * w for _ in range(h)]
cnt = 0
while s:
    q = [s.pop(0)]
    dist[q[0][0]][q[0][1]] = 0
    q[0] = tuple(q[0])
    cnt = 0
    while q:
        if cnt == (h + w - 2):
            break
        qq = []
        cnt += 1
        for y, x in q:
            for dy, dx in test:
                yy, xx = y + dy, x + dx
                if xx < 0 or yy < 0 or xx > w - 1 or yy > h - 1:
                    continue
                if a[yy][xx] == '#':
                    continue
                if dist[yy][xx] < cnt:
                    break
                dist[yy][xx] = min(cnt, dist[yy][xx])
                qq.append((yy, xx))
        q = qq
ans = 0
for i in range(h):
    for j in range(w):
        ans = max(ans, dist[i][j])
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import deque


def solve():
    H, W = map(int, input().split())
    m = [[-1]*W for _ in range(H)]
    l = [input() for _ in range(H)]
    dx = [-1, 1, 0, 0]
    dy = [0, 0, -1, 1]
    q = deque([])

    for i in range(H):
        for j in range(W):
            if l[i][j]=="#":
                q.append((i, j, 0))
                m[i][j] = 0
    
    while q:
        y, x, cost = q.popleft()
        m[y][x] = cost

        for px, py in zip(dx, dy):
            x1, y1 = x + px, y + py
            if not (0<=x1<W and 0<=y1<H):
                continue
            if m[y1][x1] == -1:
                q.append((y1, x1, cost+1))

    print(max(map(max, m)))


if __name__ == "__main__":
    solve()

Submission status: Wrong Answer

Solution code:
from collections import deque
import sys
input=sys.stdin.readline


def solve():
    H, W = map(int, input().split())
    m = [[-1]*W for _ in range(H)]
    candidate = [(i, j, 0) for i in range(H) for j, s in enumerate(input()) if s=="#"]
    q = deque(candidate)

    while q:
        y, x, cost = q.popleft()
        m[y][x] = cost

        for y1, x1 in [(y-1, x), (y+1, x), (y, x-1), (y, x+1)]:
            if not (0<=x1<W and 0<=y1<H):
                continue
            if m[y1][x1] != -1:
                q.append((y1, x1, cost+1))

    print(max(map(max, m)))


if __name__ == "__main__":
    solve()

Submission status: Wrong Answer

Solution code:
from collections import deque
import sys
input=sys.stdin.readline


def solve():
    H, W = map(int, input().split())
    dp = [[False]*W for _ in range(H)]
    candidate = []

    for i in range(H):
        for j, s in enumerate(input()):
            if s=="#":
                dp[i][j] = True
                candidate.append(((i, j), 0))

    q = deque(candidate)
    while q:
        (y, x), cost = q.popleft()
        dp[y][x] = True

        for y1, x1 in [(y+1, x), (y-1, x), (y, x-1), (y, x+1)]:
            if not (0<=y1<H and 0<=x1<W) or dp[y1][x1]:
                continue
            q.append(((y1, x1), cost+1))

    print(cost)


if __name__ == "__main__":
    solve()

Submission status: Wrong Answer

Solution code:
from collections import deque
import sys
input=sys.stdin.readline


def solve():
    H, W = map(int, input().split())
    dp = [[False]*W for _ in range(H)]
    candidate = []

    for i in range(H):
        for j, s in enumerate(input()):
            if s=="#":
                dp[i][j] = True
                candidate.append((i, j))

    q = deque([(c, 0) for c in candidate])
    while q:
        (y, x), cost = q.popleft()
        dp[y][x] = True

        for y1, x1 in [(y+1, x), (y-1, x), (y, x-1), (y, x+1)]:
            if not (0<=y1<H and 0<=x1<W):
                continue
            if dp[y1][x1]:continue
            q.append(((y1, x1), cost+1))

    print(cost)


if __name__ == "__main__":
    solve()

Submission status: Wrong Answer

Solution code:
import collections

h,w = map(int,input().split())

tizu = [list(input()) for i in range(h)]


dy = [1,0,-1,0]
dx = [0,1,0,-1]

def f(y,x):
    for i in range(4):
        newy = y + dy[i]
        newx = x + dx[i]
        if 0 <= newy and newy < h and 0 <= newx and newx < w:
            if tizu[newy][newx] == ".":
                q.append((newy,newx))
                tizu[newy][newx] = "#"
            
q = collections.deque()
for i in range(h): 
    for k in range(w):
        if tizu[i][k] == "#":
            q.append((i,k))
ans = 0
while True:
    flag = False
    l = len(q)
    for i in range(l):
        yx = q.popleft()
        f(yx[0],yx[1])
        flag = True
    if flag == False:
        print(ans)
        exit()
    ans += 1

Submission status: Wrong Answer

Solution code:
import sys
from io import StringIO
import unittest
from collections import deque
# import queue


def resolve():
    # ★get input
    h, w = map(int, input().split())

    # ★exec
    # BFSにて最短経路を求める
    # 準備
    distance = [[-1 for i in range(w)] for j in range(h)]
    que = deque()

    # スタート地点の情報を設定
    # 多点スタートの設定
    for i in range(h):
        line = list(input())
        for j in range(w):
            if line[j] == "#":
                que.append((i, j))
                distance[i][j] = 0

    # BFS開始
    while len(que) > 0:

        # now = que.get()
        now = que.popleft()

        # 上下左右のマスを確認
        for move_y, move_x in ((1, 0), (-1, 0), (0, 1), (0, -1)):

            # 盤の範囲外なら何もしない
            target = (now[0] + move_y, now[1] + move_x)
            if not (h > target[0] >= 0 and w > target[1] >= 0):
                continue

            # 距離が設定済みなら何もしない
            if not distance[target[0]][target[1]] == -1:
                continue

            # キューに追加
            # que.put(target)
            que.append(target)
            # 最短距離を設定
            distance[target[0]][target[1]] = distance[now[0]][now[1]] + 1

    # 距離が最大の点 = 答えになる。
    ans = 0
    for i in range(h):
        ans = max(ans, max(distance[i]))

    print(ans)



class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)
    def test_入力例_1(self):
        input = """3 3
...
.#.
..."""
        output = """2"""
        self.assertIO(input, output)
    def test_入力例_2(self):
        input = """6 6
..#..#
......
#..#..
......
.#....
....#."""
        output = """3"""
        self.assertIO(input, output)

if __name__ == "__main__":
    unittest.main()

Submission status: Wrong Answer

Solution code:
# pypyでlistが遅いか確認
from collections import deque


def resolve():
    # ★get input
    h, w = map(int, input().split())

    grid = [[-1 for i in range(w)] for j in range(h)]

    for i in range(h):
        # grid[i] = list(input())
        grid[i] = list(input())

        # 以下の様にsliceで取得することもできるが、パフォーマンスが若干落ちる。
        # 1000×1000件で50ミリ秒くらい差が出る?
        # line = input()
        # for j in range(w):
        #     grid[i][j] = line[j:j+1]




    ans = 0
    print(ans)


if __name__ == "__main__":
    resolve()

Submission status: Wrong Answer

Solution code:
import sys
from io import StringIO
import unittest
from collections import deque
# import queue
from collections import deque


def resolve():
    # ★get input
    h, w = map(int, input().split())

    grid = [["" for i in range(w + 2)] for j in range(h + 2)]

    for i in range(h):
        grid[i] = list(input())

        # 以下の様にsliceで取得することもできるが、パフォーマンスが若干落ちる。
        # 1000×1000件で50ミリ秒くらい差が出る?
        # line = input()
        # for j in range(w):
        #     grid[i][j] = line[j:j+1]


    # ★exec
    # BFSにて最短経路を求める
    # 準備
    distance = [[-1 for i in range(w)] for j in range(h)]
    # que = queue.Queue()
    que = deque()

    # スタート地点の情報を設定
    # 多点スタートの設定
    for i in range(h):
        for j in range(w):
            if grid[i][j] == "#":
                # que.put((i, j))
                que.append((i, j))
                distance[i][j] = 0

    # BFS開始
    while len(que) > 0:

        # now = que.get()
        now = que.popleft()

        # 上下左右のマスを確認
        for move_y, move_x in ((1, 0), (-1, 0), (0, 1), (0, -1)):

            # 盤の範囲外なら何もしない
            target = (now[0] + move_y, now[1] + move_x)
            if not h > target[0] >= 0 or not w > target[1] >= 0:
                continue

            # 黒塗りされているなら何もしない
            # この条件、不要な気がする・・
            # if grid[target[0]][target[1]] == '#':
            #     continue

            # 距離が設定済みなら何もしない
            if not distance[target[0]][target[1]] == -1:
                continue

            # キューに追加
            # que.put(target)
            que.append(target)
            # 最短距離を設定
            distance[target[0]][target[1]] = distance[now[0]][now[1]] + 1

            # 黒塗り
            # この処理、不要な気がする・・
            # grid[target[0]][target[1]] = '#'

    # 距離が最大の点 = 答えになる。
    ans = 0
    for i in range(h):
        ans = max(ans, max(distance[i]))

    print(ans)



class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)
    def test_入力例_1(self):
        input = """3 3
...
.#.
..."""
        output = """2"""
        self.assertIO(input, output)
    def test_入力例_2(self):
        input = """6 6
..#..#
......
#..#..
......
.#....
....#."""
        output = """3"""
        self.assertIO(input, output)

if __name__ == "__main__":
    unittest.main()

Submission status: Wrong Answer

Solution code:
import queue

def resolve():
    # ★get input
    h, w = map(int, input().split())

    grid = [["" for i in range(w)] for j in range(h)]

    for i in range(h):
        grid[i] = list(input())


    # ★exec
    # BFSにて最短経路を求める
    # 準備
    distance = [[-1 for i in range(w)] for j in range(h)]
    que = queue.Queue()

    # スタート地点の情報を設定
    # 多点スタートの設定
    for i in range(h):
        for j in range(w):
            if grid[i][j] == "#":
                que.put([i, j])
                distance[i][j] = 0

    # BFS開始
    while not que.empty():

        now = que.get()

        # 上下左右のマスを確認
        for move_y, move_x in ((1, 0), (-1, 0), (0, 1), (0, -1)):

            # 盤の範囲外なら何もしない
            target = (now[0] + move_y, now[1] + move_x)
            if not h > target[0] >= 0 or not w > target[1] >= 0:
                continue

            # 黒塗りされているなら何もしない
            if grid[target[0]][target[1]] == '#':
                continue

            # 距離が設定済みなら何もしない
            if not distance[target[0]][target[1]] == -1:
                continue

            # キューに追加
            que.put(target)

            # 最短距離を設定
            distance[target[0]][target[1]] = distance[now[0]][now[1]] + 1

    # 距離が最大の点 = 答えになる。
    ans = 0
    print(ans)


if __name__ == "__main__":
    resolve()

Submission status: Wrong Answer

Solution code:
import queue

def resolve():
    # ★get input
    h, w = map(int, input().split())

    grid = [["" for i in range(w)] for j in range(h)]

    for i in range(h):
        grid[i] = list(input())


    # ★exec
    # BFSにて最短経路を求める
    # 準備
    distance = [[-1 for i in range(w)] for j in range(h)]
    que = queue.Queue()

    # スタート地点の情報を設定
    # 多点スタートの設定
    for i in range(h):
        for j in range(w):
            if grid[i][j] == "#":
                que.put([i, j])
                distance[i][j] = 0

    # BFS開始
    while not que.empty():

        now = que.get()

        # 上下左右のマスを確認
        for move_y, move_x in ((1, 0), (-1, 0), (0, 1), (0, -1)):

            # 盤の範囲外なら何もしない
            target = [now[0] + move_y, now[1] + move_x]
            if not h > target[0] >= 0 or not w > target[1] >= 0:
                continue

            # 黒塗りされているなら何もしない
            if grid[target[0]][target[1]] == '#':
                continue

            # 距離が設定済みなら何もしない
            if not distance[target[0]][target[1]] == -1:
                continue

            # キューに追加
            que.put(target)

            # 最短距離を設定
            distance[target[0]][target[1]] = distance[now[0]][now[1]] + 1

    # 距離が最大の点 = 答えになる。
    ans = 0
    print(ans)


if __name__ == "__main__":
    resolve()

Submission status: Wrong Answer

Solution code:
from subprocess import call
call (('pypy3', '-c', """
    from collections import deque

    def main():
    import queue

    def resolve():
        # ★get input
        h, w = map(int, input().split())

        grid = [["" for i in range(w)] for j in range(h)]

        for i in range(h):
            grid[i] = list(input())


        # ★exec
        # BFSにて最短経路を求める
        # 準備
        distance = [[-1 for i in range(w)] for j in range(h)]
        que = queue.Queue()

        # スタート地点の情報を設定
        # 多点スタートの設定
        for i in range(h):
            for j in range(w):
                if grid[i][j] == "#":
                    que.put([i, j])
                    distance[i][j] = 0

        # BFS開始
        while not que.empty():

            now = que.get()

            # 上下左右のマスを確認
            for move_y, move_x in ((1, 0), (-1, 0), (0, 1), (0, -1)):

                # 盤の範囲外なら何もしない
                target = [now[0] + move_y, now[1] + move_x]
                if not h > target[0] >= 0 or not w > target[1] >= 0:
                    continue

                # 黒塗りされているなら何もしない
                if grid[target[0]][target[1]] == '#':
                    continue

                # 距離が設定済みなら何もしない
                if not distance[target[0]][target[1]] == -1:
                    continue

                # キューに追加
                que.put(target)

                # 最短距離を設定
                distance[target[0]][target[1]] = distance[now[0]][now[1]] + 1

        # 距離が最大の点 = 答えになる。
        ans = 0
        for i in range(h):
            ans = max(ans, max(distance[i]))

        print(ans)
    
main()
 
"""))

Submission status: Wrong Answer

Solution code:
import queue

def resolve():
    # ★get input
    h, w = map(int, input().split())

    grid = [["" for i in range(w)] for j in range(h)]

    for i in range(h):
        line = list(input())
        for j in range(w):
            grid[i][j] = line[j]



if __name__ == "__main__":
    resolve()

Submission status: Wrong Answer

Solution code:
import queue

def resolve():
    # ★get input
    h, w = map(int, input().split())

    grid = [["" for i in range(w)] for j in range(h)]

    for i in range(h):
        line = input()
        for j in range(w):
            grid[i][j] = line[j:j+1]



if __name__ == "__main__":
    resolve()

Submission status: Wrong Answer

Solution code:
from collections import deque

h,w = map(int,input().split())
field = [ list(input()) for _ in range(h) ]

visited = [ [float("inf")]*w for _ in range(h) ]
q = deque()

for j in range(h):
    for i in range(w):
        a = field[j][i]
        if a=="#":
            q.append([j,i,0])
            visited[j][i] = 1
        else:
            pass

m = 0
while q:
    y,x,d = q.popleft()
    for j,i in ([1,0],[0,-1],[-1,0],[0,1]):
        ny = y + j
        nx = x + i
        if ny==-1 or nx==-1 or ny==h or nx==w:
            pass
        elif visited[ny][nx]==0:
            visited[ny][nx] = 1
            q.append([ny,nx,d+1])
            m = max(m,d+1)   
print(m)

Submission status: Wrong Answer

Solution code:
from collections import deque

h,w = map(int,input().split())
field = [ list(input()) for _ in range(h) ]

visited = [ [float("inf")]*w for _ in range(h) ]
q = deque()

for j in range(h):
    for i in range(w):
        a = field[j][i]
        if a=="#":
            q.append([j,i,0])
            visited[j][i] = 1
        else:
            pass

m = 0
while q:
    y,x,d = q.popleft()
    for j,i in ([1,0],[0,-1],[-1,0],[0,1]):
        ny = y + j
        nx = x + i
        if ny==-1 or nx==-1 or ny==h or nx==w:
            pass
        elif visited[ny][nx]==0:
            visited[ny][nx] = 1
            q.append([ny,nx,d+1])
            m = max(m,d[ny][nx])   
print(m)

Submission status: Wrong Answer

Solution code:
h,w=map(int,input().split())
field=[list(input()) for i in range(h)]
black=[[True]*w for i in range(h)]

from copy import deepcopy

option=set()
for i in range(h):
    for j in range(w):
        if field[i][j]=="#":
            black[i][j]=False
            option.add((i,j))
direction=[(-1,0),(1,0),(0,-1),(0,1)]
cnt=0
new_option=set()
flag=True
while flag:
    flag=False
    for y,x in option:
        for dy,dx in direction:
            ny,nx=y+dy,x+dx
            if 0<=ny<=h-1 and 0<=nx<=w-1 and field[ny][nx]==".":
                new_option.add((ny,nx))
                black[ny][nx]=False
    option=deepcopy(new_option)
    new_option.clear()
    cnt+=1
    for i in black:
        for j in i:
            if j==True:
                flag=True
                break
print(cnt)

Submission status: Wrong Answer

Solution code:
import numpy as np
import sys
sys.setrecursionlimit(10 ** 5 + 10)
# input = sys.stdin.readline

def resolve():

    from collections import deque

    H, W = map(int, input().split())
    maze = [input() for i in range(H)]
    visited = [[-1] * W for j in range(H)]
    start_list=[]
    for i in range(H):
        for j in range(W):
            if maze[i][j]=='#':
                start_list.append([i,j])



    def bfs(maze, visited, sy, sx):
        queue = deque([[sy, sx]])
        visited[sy][sx] = 0
        while queue:
            y, x = queue.popleft()
            for j, k in ([1, 0], [-1, 0], [0, 1], [0, -1]):
                ny, nx = y + j, x + k
                if 0 <= ny < H and 0 <= nx < W and \
                        maze[ny][nx] == "." and (visited[ny][nx]==-1 or (visited[ny][nx]!=-1 and visited[y][x] + 1<visited[ny][nx])):
                    visited[ny][nx] = visited[y][x] + 1
                    queue.append([ny, nx])
                if 0 <= ny < H and 0 <= nx < W and \
                        maze[ny][nx] == "#":
                    return visited

    for [i,j] in start_list:
        bfs(maze, visited, i, j)
    print(np.amax(visited)+1)


resolve()

Submission status: Wrong Answer

Solution code:
import numpy as np

def main():
  H,W = map(int,input().split())
  maze = [list(input())for _ in range(H)]
  for i in range(H):
    for j in range(W):
      if maze[i][j]=="#":
        maze[i][j]=0
      else:
        maze[i][j]=float('INF')
  maze = np.array(maze)
  for i in range(1,H):
    maze[i,:]=np.minimum(maze[i,:],maze[i-1,:]+1)
  for i in range(H-2,-1,-1):
    maze[i,:]=np.minimum(maze[i,:],maze[i+1,:]+1)
  for i in range(1,W):
    maze[:,i]=np.minimum(maze[:,i],maze[:,i-1]+1)
  for i in range(W-2,-1,-1):
    maze[:,i]=np.minimum(maze[:,i],maze[:,i+1]+1)
  print(np.max(maze))
main()

Submission status: Wrong Answer

Solution code:
import numpy as np

def main():
  H,W = map(int,input().split())
  maze = [list(input())for _ in range(H)]
  for i in range(H):
    for j in range(W):
      if maze[i][j]=="#":
        maze[i][j]=0
      else:
        maze[i][j]=float('INF')
  
  for i in range(1,H):
    maze[i,:]=np.minimum(maze[i,:],maze[i-1,:]+1)
  for i in range(H-2,-1,-1):
    maze[i,:]=np.minimum(maze[i,:],maze[i+1,:]+1)
  for i in range(1,W):
    maze[:,i]=np.minimum(maze[:,i],maze[:,i-1]+1)
  for i in range(W-2,-1,-1):
    maze[:,i]=np.minimum(maze[:,i],maze[:,i+1]+1)
  print(np.max(maze))

Submission status: Wrong Answer

Solution code:
from collections import deque

H, W = map(int, input().split())
data = deque()

for y in range(H):
    for x, v in enumerate(input()):
        if v == '#':
            data.append((y, x))

ans = [[-1 for _ in range(W)] for __ in range(H)]

for v in data:
    ans[v[0]][v[1]] = 0


d = 0
while len(data):
    print(data)
    y, x = data.popleft()
    d = ans[y][x]

    for i, j in ((-1, 0), (1, 0), (0, -1), (0, 1)):
        new_y = y + i
        new_x = x + j
        if new_y < 0 or H <= new_y or new_x < 0 or W <= new_x:
            continue
        if ans[new_y][new_x] == -1:
            ans[new_y][new_x] = d + 1
            data.append((new_y, new_x))

print(max([a for aa in ans for a in aa]))

Submission status: Wrong Answer

Solution code:
H, W = map(int, input().split())
data = []

for y in range(H):
    for x, v in enumerate(input()):
        if v == '#':
            data.append([y, x, [], 0])

inf = H * W + 10
ans = [[inf for _ in range(W)] for __ in range(H)]

for v in data:
    ans[v[0]][v[1]] = 0

def check(destination, origin):
    return [destination[0], destination[1]] not in origin[2]

def cnt_update(ans, v):
    ans[v[0], v[1]] = v[3] + 1
"""
BFSまとめ
0. 現在位置、履歴、アクション数の3要素が必要
1. 更新する, アクション数を加算する
2. 条件を一致しているか、履歴に入っていないかを確認
3. popをループ
"""

fin = 0

while len(data):
    v = data.pop()
    v[2].append([v[0], v[1]])

    if v[1] - 1 >= 0 and ans[v[0]][v[1] - 1] > v[3] + 1:
        v_left = [v[0], v[1] - 1, v[2], v[3] + 1]
        if check(v_left, v):
            ans[v_left[0]][v_left[1]] = v_left[3]
            data.append(v_left)
            if fin < v[3] + 1:
                fin = v[3] + 1

    if v[1] + 1 <= W - 1 and ans[v[0]][v[1] + 1] > v[3] + 1:
        v_right = [v[0], v[1] + 1, v[2], v[3] + 1]
        if check(v_right, v):
            ans[v_right[0]][v_right[1]] = v_right[3]
            data.append(v_right)
            if fin < v[3] + 1:
                fin = v[3] + 1

    if v[0] - 1 >= 0 and ans[v[0] - 1][v[1]] > v[3] + 1:
        v_up = [v[0] - 1, v[1], v[2], v[3] + 1]
        if check(v_up, v):
            ans[v_up[0]][v_up[1]] = v_up[3]
            data.append(v_up)
            if fin < v[3] + 1:
                fin = v[3] + 1

    if v[0] + 1 <= H - 1 and ans[v[0] + 1][v[1]] > v[3] + 1:
        v_down = [v[0] + 1, v[1], v[2], v[3] + 1]
        if check(v_down, v):
            ans[v_down[0]][v_down[1]] = v_down[3]
            data.append(v_down)
            if fin < v[3] + 1:
                fin = v[3] + 1

# print(max([a for aa in ans for a in aa]))
print(fin)