Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
h, w = map(int, input().split())

field = [] # 白黒情報を持つリスト
mark = [] # 操作回数を保持するリスト
INF = 10**6

for i in range(h):
    field.append(list(input()))
    mark.append([0 for i in range(w)])

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

queue = deque()
for i in range(h):
    for j in range(w):
        if field[i][j] == "#":
            queue.append([i, j])

while len(queue) > 0:
    y, x = queue.popleft()
    for k in range(4):
        nx = x + dx[k]
        ny = y + dy[k]
        if 0 <= ny < h and 0 <= nx < w:
            if field[ny][nx] == ".":
                mark[ny][nx] = mark[y][x] + 1
                queue.append([ny, nx])
                field[ny][nx] = "#"

ans=0

for i in mark:
    ans = max(ans, max(i))

print(ans)


Fixed submission:
from collections import deque
h, w = map(int, input().split())

field = [] # 白黒情報を持つリスト
mark = [] # 操作回数を保持するリスト
INF = 10**6

for i in range(h):
    field.append(list(input()))
    mark.append([0 for i in range(w)])

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

queue = deque()
for i in range(h):
    for j in range(w):
        if field[i][j] == "#":
            queue.append([i, j])

while len(queue) > 0:
    y, x = queue.popleft()
    for k in range(4):
        nx = x + dx[k]
        ny = y + dy[k]
        if 0 <= ny < h and 0 <= nx < w:
            if field[ny][nx] == ".":
                mark[ny][nx] = mark[y][x] + 1
                queue.append([ny, nx])
                field[ny][nx] = "#"

ans=0

for i in mark:
    ans = max(ans, max(i))

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque

h, w = map(int,input().split())
hw = [input() for i in range(h)]
#for i in range(h):
#    hw.append(input())

# used = [True]*h*w
isBlack = [[None]*w for i in range(h)]

queue = deque([])
for i in range(h):
    for j in range(w):
        if hw[i][j] == '#':
            queue.append([i, j, 0])# h, w, step count
            isBlack[i][j] = True

res = 0
while len(queue) > 0:
    ph, pw, pcnt = queue.popleft()
    if ph > 0 and not isBlack[ph-1][pw]:
        queue.append([ph-1, pw, pcnt+1])
        isBlack[ph-1][pw] = True
    if ph < h-1 and not isBlack[ph+1][pw]:
        queue.append([ph+1, pw, pcnt+1])
        isBlack[ph+1][pw] = True
    if pw > 0 and not isBlack[ph][pw-1]:
        queue.append([ph, pw-1, pcnt+1])
        isBlack[ph][pw-1] = True
    if pw < w-1 and not isBlack[ph][pw+1]:
        queue.append([ph, pw+1, pcnt+1])
        isBlack[ph][pw+1] = True
    #print(queue)
    res = pcnt
print(res)


Fixed submission:
from collections import deque
h, w = map(int, input().split())

field = [] # 白黒情報を持つリスト
mark = [] # 操作回数を保持するリスト
INF = 10**6

for i in range(h):
    field.append(list(input()))
    mark.append([0 for i in range(w)])

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

queue = deque()
for i in range(h):
    for j in range(w):
        if field[i][j] == "#":
            queue.append([i, j])

while len(queue) > 0:
    y, x = queue.popleft()
    for k in range(4):
        nx = x + dx[k]
        ny = y + dy[k]
        if 0 <= ny < h and 0 <= nx < w:
            if field[ny][nx] == ".":
                mark[ny][nx] = mark[y][x] + 1
                queue.append([ny, nx])
                field[ny][nx] = "#"

ans=0

for i in mark:
    ans = max(ans, max(i))

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque

h,w = map(int,input().split())
hw = [input() for i in range(h)]
#for i in range(h):
#    hw.append(input())

# used = [True]*h*w
isWhite = [[True]*w for i in range(h)]

queue = deque([])
for i in range(h):
    for j in range(w):
        if hw[i][j] == '#':
            queue.append([i,j,0])# h, w, step count
            isWhite[i][j] = False

res = 0
while len(queue) > 0:
    ph, pw, pcnt = queue.popleft()
    if ph > 0 and isWhite[ph-1][pw]:
        queue.append([ph-1, pw, pcnt+1])
        isWhite[ph-1][pw] = False
    if ph < h-1 and isWhite[ph+1][pw]:
        queue.append([ph+1, pw, pcnt+1])
        isWhite[ph+1][pw] = False
    if pw > 0 and isWhite[ph][pw-1]:
        queue.append([ph, pw-1, pcnt+1])
        isWhite[ph][pw-1] = False
    if pw < w-1 and isWhite[ph][pw+1]:
        queue.append([ph, pw+1, pcnt+1])
        isWhite[ph][pw+1] = False
#        print(queue)
    res = pcnt
print(res)


Fixed submission:
from collections import deque
h, w = map(int, input().split())

field = [] # 白黒情報を持つリスト
mark = [] # 操作回数を保持するリスト
INF = 10**6

for i in range(h):
    field.append(list(input()))
    mark.append([0 for i in range(w)])

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

queue = deque()
for i in range(h):
    for j in range(w):
        if field[i][j] == "#":
            queue.append([i, j])

while len(queue) > 0:
    y, x = queue.popleft()
    for k in range(4):
        nx = x + dx[k]
        ny = y + dy[k]
        if 0 <= ny < h and 0 <= nx < w:
            if field[ny][nx] == ".":
                mark[ny][nx] = mark[y][x] + 1
                queue.append([ny, nx])
                field[ny][nx] = "#"

ans=0

for i in mark:
    ans = max(ans, max(i))

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque

h,w = map(int,input().split())
hw = [input() for i in range(h)]
#for i in range(h):
#    hw.append(input())

# used = [True]*h*w
isWhite = [[True]*w for i in range(h)]

queue = deque([])
for i in range(h):
    for j in range(w):
        if hw[i][j] == '#':
            queue.append([i,j,0])# h, w, step count
            isWhite[i][j] = False

res = 0
while len(queue) > 0:
    pos = queue.popleft()
    if pos[0] > 0 and isWhite[pos[0]-1][pos[1]]:
        queue.append([pos[0]-1, pos[1], pos[2]+1])
        isWhite[pos[0]-1][pos[1]] = False
    if pos[0] < h-1 and isWhite[pos[0]+1][pos[1]]:
        queue.append([pos[0]+1, pos[1], pos[2]+1])
        isWhite[pos[0]+1][pos[1]] = False
    if pos[1] > 0 and isWhite[pos[0]][pos[1]-1]:
        queue.append([pos[0], pos[1]-1, pos[2]+1])
        isWhite[pos[0]][pos[1]-1] = False
    if pos[1] < w-1 and isWhite[pos[0]][pos[1]+1]:
        queue.append([pos[0], pos[1]+1, pos[2]+1])
        isWhite[pos[0]][pos[1]+1] = False
#        print(queue)
    res = pos[2]
print(res)


Fixed submission:
from collections import deque
h, w = map(int, input().split())

field = [] # 白黒情報を持つリスト
mark = [] # 操作回数を保持するリスト
INF = 10**6

for i in range(h):
    field.append(list(input()))
    mark.append([0 for i in range(w)])

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

queue = deque()
for i in range(h):
    for j in range(w):
        if field[i][j] == "#":
            queue.append([i, j])

while len(queue) > 0:
    y, x = queue.popleft()
    for k in range(4):
        nx = x + dx[k]
        ny = y + dy[k]
        if 0 <= ny < h and 0 <= nx < w:
            if field[ny][nx] == ".":
                mark[ny][nx] = mark[y][x] + 1
                queue.append([ny, nx])
                field[ny][nx] = "#"

ans=0

for i in mark:
    ans = max(ans, max(i))

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque

h,w = map(int,input().split())
hw = [input() for i in range(h)]
#for i in range(h):
#    hw.append(input())

# used = [True]*h*w
isWhite = [[True]*w for i in range(h)]

queue = deque([])
for i in range(h):
    for j in range(w):
        if hw[i][j] == '#':
            queue.append([i,j])
            isWhite[i][j] = False

res = 0
while queue:
    nextQueue = deque([])
    for pos in queue:
        if pos[0] > 0 and isWhite[pos[0]-1][pos[1]]:
            nextQueue.append([pos[0]-1,pos[1]])
            isWhite[pos[0]-1][pos[1]] = False
        if pos[0] < h-1 and isWhite[pos[0]+1][pos[1]]:
            nextQueue.append([pos[0]+1,pos[1]])
            isWhite[pos[0]+1][pos[1]] = False
        if pos[1] > 0 and isWhite[pos[0]][pos[1]-1]:
            nextQueue.append([pos[0],pos[1]-1])
            isWhite[pos[0]][pos[1]-1] = False
        if pos[1] < w-1 and isWhite[pos[0]][pos[1]+1]:
            nextQueue.append([pos[0],pos[1]+1])
            isWhite[pos[0]][pos[1]+1] = False
            
#        print(queue)
    queue = nextQueue
    res += 1
print(res-1)


Fixed submission:
from collections import deque
h, w = map(int, input().split())

field = [] # 白黒情報を持つリスト
mark = [] # 操作回数を保持するリスト
INF = 10**6

for i in range(h):
    field.append(list(input()))
    mark.append([0 for i in range(w)])

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

queue = deque()
for i in range(h):
    for j in range(w):
        if field[i][j] == "#":
            queue.append([i, j])

while len(queue) > 0:
    y, x = queue.popleft()
    for k in range(4):
        nx = x + dx[k]
        ny = y + dy[k]
        if 0 <= ny < h and 0 <= nx < w:
            if field[ny][nx] == ".":
                mark[ny][nx] = mark[y][x] + 1
                queue.append([ny, nx])
                field[ny][nx] = "#"

ans=0

for i in mark:
    ans = max(ans, max(i))

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque

h,w = map(int,input().split())
hw = []
for i in range(h):
    hw.append(input())

# used = [True]*h*w
isWhite = [[True]*w for i in range(h)]

queue = deque([])
for i in range(h):
    for j in range(w):
        if hw[i][j] == '#':
            queue.append([i,j])
            isWhite[i][j] = False

res = 0
while queue:
    nextQueue = []
    for pos in queue:
        if pos[0] > 0 and isWhite[pos[0]-1][pos[1]]:
            nextQueue.append([pos[0]-1,pos[1]])
            isWhite[pos[0]-1][pos[1]] = False
        if pos[0] < h-1 and isWhite[pos[0]+1][pos[1]]:
            nextQueue.append([pos[0]+1,pos[1]])
            isWhite[pos[0]+1][pos[1]] = False
        if pos[1] > 0 and isWhite[pos[0]][pos[1]-1]:
            nextQueue.append([pos[0],pos[1]-1])
            isWhite[pos[0]][pos[1]-1] = False
        if pos[1] < w-1 and isWhite[pos[0]][pos[1]+1]:
            nextQueue.append([pos[0],pos[1]+1])
            isWhite[pos[0]][pos[1]+1] = False
    queue = nextQueue
    res += 1
print(res-1)

Fixed submission:
from collections import deque
h, w = map(int, input().split())

field = [] # 白黒情報を持つリスト
mark = [] # 操作回数を保持するリスト
INF = 10**6

for i in range(h):
    field.append(list(input()))
    mark.append([0 for i in range(w)])

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

queue = deque()
for i in range(h):
    for j in range(w):
        if field[i][j] == "#":
            queue.append([i, j])

while len(queue) > 0:
    y, x = queue.popleft()
    for k in range(4):
        nx = x + dx[k]
        ny = y + dy[k]
        if 0 <= ny < h and 0 <= nx < w:
            if field[ny][nx] == ".":
                mark[ny][nx] = mark[y][x] + 1
                queue.append([ny, nx])
                field[ny][nx] = "#"

ans=0

for i in mark:
    ans = max(ans, max(i))

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
# "#"=black, "."=white
import copy

H, W = map(int, input().split())
HW = []
for i in range(H):
  HW.append(list(input()))
# print(HW)

def whiteCount(HWlist):
  return [flatten for inner in HWlist for flatten in inner].count(".")    

pHW = copy.deepcopy(HW)
turnCnt=0
while(whiteCount(HW)):
  for i in range(H):
    for j in range(W):
      if HW[i][j] == ".":
        if (i > 0 and HW[i-1][j] == "#") or \
           (i < H-1 and HW[i+1][j] == "#") or \
           (j > 0 and HW[i][j-1] == "#") or \
           (j < W-1 and HW[i][j+1] == "#"):
          pHW[i][j] = "#"
  turnCnt += 1
  HW = copy.deepcopy(pHW)
  # print(pHW)
print(turnCnt)


Fixed submission:
from collections import deque
h, w = map(int, input().split())

field = [] # 白黒情報を持つリスト
mark = [] # 操作回数を保持するリスト
INF = 10**6

for i in range(h):
    field.append(list(input()))
    mark.append([0 for i in range(w)])

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

queue = deque()
for i in range(h):
    for j in range(w):
        if field[i][j] == "#":
            queue.append([i, j])

while len(queue) > 0:
    y, x = queue.popleft()
    for k in range(4):
        nx = x + dx[k]
        ny = y + dy[k]
        if 0 <= ny < h and 0 <= nx < w:
            if field[ny][nx] == ".":
                mark[ny][nx] = mark[y][x] + 1
                queue.append([ny, nx])
                field[ny][nx] = "#"

ans=0

for i in mark:
    ans = max(ans, max(i))

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
# "#"=black, "."=white
import copy

H, W = map(int, input().split())
HW = []
for i in range(H):
  HW.append(list(input()))
# print(HW)

def whiteCount(HWlist):
  return [flatten for inner in HWlist for flatten in inner].count(".")    

pHW = copy.deepcopy(HW)
turnCnt=0
while(whiteCount(HW)):
  for i in range(H):
    for j in range(W):
      if HW[i][j] == "#":
        if i > 0:
          pHW[i-1][j] = "#"
        if i < H-1:
          pHW[i+1][j] = "#"
        if j > 0:
          pHW[i][j-1] = "#"
        if j < W-1:
          pHW[i][j+1] = "#"
  turnCnt += 1
  HW = copy.deepcopy(pHW)
  # print(pHW)
print(turnCnt)


Fixed submission:
from collections import deque
h, w = map(int, input().split())

field = [] # 白黒情報を持つリスト
mark = [] # 操作回数を保持するリスト
INF = 10**6

for i in range(h):
    field.append(list(input()))
    mark.append([0 for i in range(w)])

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

queue = deque()
for i in range(h):
    for j in range(w):
        if field[i][j] == "#":
            queue.append([i, j])

while len(queue) > 0:
    y, x = queue.popleft()
    for k in range(4):
        nx = x + dx[k]
        ny = y + dy[k]
        if 0 <= ny < h and 0 <= nx < w:
            if field[ny][nx] == ".":
                mark[ny][nx] = mark[y][x] + 1
                queue.append([ny, nx])
                field[ny][nx] = "#"

ans=0

for i in mark:
    ans = max(ans, max(i))

print(ans)