Buggy python submission (verdict: Time Limit Exceeded):
h,w = map(int,input().split())
a = [input() for _ in range(h)]
ans = 0
queue = []
for i in range(h):
    for j in range(w):
        if a[i][j]=='#':
            queue.append([i,j])
from collections import deque
queue = deque(queue)
dxy = [(0,1), (0,-1), (1,0), (-1,0)]
dp = [[10**4]*w for _ in range(h)]
for i,j in queue:
    dp[i][j] = 0
while len(queue):
    y,x = queue.popleft()
    d = dp[y][x]
    for dx,dy in dxy:
        nx, ny = x+dx, y+dy
        if not 0<=nx<=w-1:
            continue
        elif not 0<=ny<=h-1:
            continue
        elif dp[ny][nx]<=d+1:
            continue
        dp[ny][nx] = d+1
        queue.append((ny,nx))
print(max([max(dp[row]) for row in range(h)]))

Fixed submission:
h,w = map(int,input().split())
a = [input() for _ in range(h)]
ans = 0
queue = []
for i in range(h):
    for j in range(w):
        if a[i][j]=='#':
            queue.append([i,j])
from collections import deque
queue = deque(queue)
dxy = [(0,1), (0,-1), (1,0), (-1,0)]
dp = [[10**4]*w for _ in range(h)]
for i,j in queue:
    dp[i][j] = 0
while len(queue):
    y,x = queue.popleft()
    d = dp[y][x]
    for dx,dy in dxy:
        nx, ny = x+dx, y+dy
        if not 0<=nx<=w-1:
            continue
        elif not 0<=ny<=h-1:
            continue
        elif dp[ny][nx]<=d+1:
            continue
        dp[ny][nx] = d+1
        queue.append((ny,nx))
print(max([max(dp[row]) for row in range(h)]))

Buggy python submission (verdict: Time Limit Exceeded):
h,w = map(int,input().split())
a = ['#'*(w+2)]+['#'+input()+'#' for _ in range(h)]+['#'*(w+2)]
ans = 0
queue = []
for i in range(1,h+1):
    for j in range(1,w+1):
        if a[i][j]=='#':
            queue.append([i,j])
from collections import deque
queue = deque(queue)
while len(queue):
    l = []
    for _ in range(len(queue)):
        q = queue.pop()
        if q[0]>1 and a[q[0]-1][q[1]]=='.':
            l.append([q[0]-1,q[1]])
        if q[1]>1 and a[q[0]][q[1]-1]=='.':
            l.append([q[0],q[1]-1])
        if q[0]<h and a[q[0]+1][q[1]]=='.':
            l.append([q[0]+1,q[1]])
        if q[1]<w and a[q[0]][q[1]+1]=='.':
            l.append([q[0],q[1]+1])
        a[q[0]-1] = a[q[0]-1][:q[1]]+'#'+a[q[0]-1][q[1]+1:]
        a[q[0]] = a[q[0]][:q[1]-1]+'###'+a[q[0]][q[1]+2:]
        a[q[0]+1] = a[q[0]+1][:q[1]]+'#'+a[q[0]+1][q[1]+1:]
    queue = deque(l)
    ans += 1
print(ans-1)

Fixed submission:
h,w = map(int,input().split())
a = [input() for _ in range(h)]
ans = 0
queue = []
for i in range(h):
    for j in range(w):
        if a[i][j]=='#':
            queue.append([i,j])
from collections import deque
queue = deque(queue)
dxy = [(0,1), (0,-1), (1,0), (-1,0)]
dp = [[10**4]*w for _ in range(h)]
for i,j in queue:
    dp[i][j] = 0
while len(queue):
    y,x = queue.popleft()
    d = dp[y][x]
    for dx,dy in dxy:
        nx, ny = x+dx, y+dy
        if not 0<=nx<=w-1:
            continue
        elif not 0<=ny<=h-1:
            continue
        elif dp[ny][nx]<=d+1:
            continue
        dp[ny][nx] = d+1
        queue.append((ny,nx))
print(max([max(dp[row]) for row in range(h)]))

Buggy python submission (verdict: Time Limit Exceeded):
h,w = map(int,input().split())
a = ['#'*(w+2)]+['#'+input()+'#' for _ in range(h)]+['#'*(w+2)]
ans = 0
queue = []
for i in range(1,h+1):
    for j in range(1,w+1):
        if a[i][j]=='#':
            queue.append([i,j])
while True:
    if queue == []:
        break
    l = []
    for _ in range(len(queue)):
        q = queue.pop()
        if q[0]>1 and a[q[0]-1][q[1]]=='.':
            l.append([q[0]-1,q[1]])
        if q[1]>1 and a[q[0]][q[1]-1]=='.':
            l.append([q[0],q[1]-1])
        if q[0]<h and a[q[0]+1][q[1]]=='.':
            l.append([q[0]+1,q[1]])
        if q[1]<w and a[q[0]][q[1]+1]=='.':
            l.append([q[0],q[1]+1])
        a[q[0]-1] = a[q[0]-1][:q[1]]+'#'+a[q[0]-1][q[1]+1:]
        a[q[0]] = a[q[0]][:q[1]-1]+'###'+a[q[0]][q[1]+2:]
        a[q[0]+1] = a[q[0]+1][:q[1]]+'#'+a[q[0]+1][q[1]+1:]
    queue = l
    ans += 1
print(ans-1)

Fixed submission:
h,w = map(int,input().split())
a = [input() for _ in range(h)]
ans = 0
queue = []
for i in range(h):
    for j in range(w):
        if a[i][j]=='#':
            queue.append([i,j])
from collections import deque
queue = deque(queue)
dxy = [(0,1), (0,-1), (1,0), (-1,0)]
dp = [[10**4]*w for _ in range(h)]
for i,j in queue:
    dp[i][j] = 0
while len(queue):
    y,x = queue.popleft()
    d = dp[y][x]
    for dx,dy in dxy:
        nx, ny = x+dx, y+dy
        if not 0<=nx<=w-1:
            continue
        elif not 0<=ny<=h-1:
            continue
        elif dp[ny][nx]<=d+1:
            continue
        dp[ny][nx] = d+1
        queue.append((ny,nx))
print(max([max(dp[row]) for row in range(h)]))

Buggy python submission (verdict: Time Limit Exceeded):
h,w = map(int,input().split())
a = ['#'*(w+2)]+['#'+input()+'#' for _ in range(h)]+['#'*(w+2)]
ans = 0
queue = []
for i in range(1,h+1):
    for j in range(1,w+1):
        if a[i][j]=='#':
            queue.append([i,j])
while True:
    if queue == []:
        break
    l = []
    for _ in range(len(queue)):
        q = queue.pop()
        if q[0]>1 and a[q[0]-1][q[1]]=='.':
            l.append([q[0]-1,q[1]])
        if q[1]>1 and a[q[0]][q[1]-1]=='.':
            l.append([q[0],q[1]-1])
        if q[0]<h and a[q[0]+1][q[1]]=='.':
            l.append([q[0]+1,q[1]])
        if q[1]<w and a[q[0]][q[1]+1]=='.':
            l.append([q[0],q[1]+1])
        a[q[0]-1] = a[q[0]-1][:q[1]]+'#'+a[q[0]-1][q[1]+1:]
        a[q[0]] = a[q[0]][:q[1]-1]+'###'+a[q[0]][q[1]+2:]
        a[q[0]+1] = a[q[0]+1][:q[1]]+'#'+a[q[0]+1][q[1]+1:]
    queue = l
    ans += 1
print(ans-1)

Fixed submission:
h,w = map(int,input().split())
a = [input() for _ in range(h)]
ans = 0
queue = []
for i in range(h):
    for j in range(w):
        if a[i][j]=='#':
            queue.append([i,j])
from collections import deque
queue = deque(queue)
dxy = [(0,1), (0,-1), (1,0), (-1,0)]
dp = [[10**4]*w for _ in range(h)]
for i,j in queue:
    dp[i][j] = 0
while len(queue):
    y,x = queue.popleft()
    d = dp[y][x]
    for dx,dy in dxy:
        nx, ny = x+dx, y+dy
        if not 0<=nx<=w-1:
            continue
        elif not 0<=ny<=h-1:
            continue
        elif dp[ny][nx]<=d+1:
            continue
        dp[ny][nx] = d+1
        queue.append((ny,nx))
print(max([max(dp[row]) for row in range(h)]))

Buggy python submission (verdict: Time Limit Exceeded):
h,w = map(int,input().split())
a = ['#'*(w+2)]+['#'+input()+'#' for _ in range(h)]+['#'*(w+2)]
ans = 0
queue = []
while True:
    l = []
    for i in range(1,h+1):
        for j in range(1,w+1):
            if not [i,j] in queue and a[i][j]=='#':
                queue += [[i,j]]
                l += [[i,j]]
    if len(queue)==h*w:
        break
    ans += 1
    for l_ in l:
        a[l_[0]-1] = a[l_[0]-1][:l_[1]]+'#'+a[l_[0]-1][l_[1]+1:]
        a[l_[0]] = a[l_[0]][:l_[1]-1]+'###'+a[l_[0]][l_[1]+2:]
        a[l_[0]+1] = a[l_[0]+1][:l_[1]]+'#'+a[l_[0]+1][l_[1]+1:]
print(ans)

Fixed submission:
h,w = map(int,input().split())
a = [input() for _ in range(h)]
ans = 0
queue = []
for i in range(h):
    for j in range(w):
        if a[i][j]=='#':
            queue.append([i,j])
from collections import deque
queue = deque(queue)
dxy = [(0,1), (0,-1), (1,0), (-1,0)]
dp = [[10**4]*w for _ in range(h)]
for i,j in queue:
    dp[i][j] = 0
while len(queue):
    y,x = queue.popleft()
    d = dp[y][x]
    for dx,dy in dxy:
        nx, ny = x+dx, y+dy
        if not 0<=nx<=w-1:
            continue
        elif not 0<=ny<=h-1:
            continue
        elif dp[ny][nx]<=d+1:
            continue
        dp[ny][nx] = d+1
        queue.append((ny,nx))
print(max([max(dp[row]) for row in range(h)]))

Buggy python submission (verdict: Time Limit Exceeded):
h,w = map(int,input().split())
a = ['#'*(w+2)]+['#'+input()+'#' for _ in range(h)]+['#'*(w+2)]
ans = 0
while True:
    l = []
    for i in range(1,h+1):
        for j in range(1,w+1):
            if a[i][j]=='#':
                l += [[i,j]]
    if len(l)==h*w:
        break
    ans += 1
    for l_ in l:
        a[l_[0]-1] = a[l_[0]-1][:l_[1]]+'#'+a[l_[0]-1][l_[1]+1:]
        a[l_[0]] = a[l_[0]][:l_[1]-1]+'###'+a[l_[0]][l_[1]+2:]
        a[l_[0]+1] = a[l_[0]+1][:l_[1]]+'#'+a[l_[0]+1][l_[1]+1:]
print(ans)

Fixed submission:
h,w = map(int,input().split())
a = [input() for _ in range(h)]
ans = 0
queue = []
for i in range(h):
    for j in range(w):
        if a[i][j]=='#':
            queue.append([i,j])
from collections import deque
queue = deque(queue)
dxy = [(0,1), (0,-1), (1,0), (-1,0)]
dp = [[10**4]*w for _ in range(h)]
for i,j in queue:
    dp[i][j] = 0
while len(queue):
    y,x = queue.popleft()
    d = dp[y][x]
    for dx,dy in dxy:
        nx, ny = x+dx, y+dy
        if not 0<=nx<=w-1:
            continue
        elif not 0<=ny<=h-1:
            continue
        elif dp[ny][nx]<=d+1:
            continue
        dp[ny][nx] = d+1
        queue.append((ny,nx))
print(max([max(dp[row]) for row in range(h)]))

Buggy python submission (verdict: Runtime Error):
h,w = map(int,input().split())
a = ['#'*(w+2)]+['#'+input()+'#' for _ in range(h)]+['#'*(w+2)]
ans = 0
while True:
    l = []
    for i in range(1,h+1):
        for j in range(1,w+1):
            if a[i][j]=='#':
                l += [i,j]
    if len(l)==h*w:
        break
    ans += 1
    for l_ in l:
        a[l_[0]-1] = a[l_[0]-1][:l_[1]]+'#'+a[l_[0]-1][l_[1]+1:]
        a[l_[0]] = a[l_[0]][:l_[1]-1]+'###'+a[l_[0]][l_[1]+2:]
        a[l_[0]+1] = a[l_[0]+1][:l_[1]]+'#'+a[l_[0]+1][l_[1]+1:]
print(ans)

Fixed submission:
h,w = map(int,input().split())
a = [input() for _ in range(h)]
ans = 0
queue = []
for i in range(h):
    for j in range(w):
        if a[i][j]=='#':
            queue.append([i,j])
from collections import deque
queue = deque(queue)
dxy = [(0,1), (0,-1), (1,0), (-1,0)]
dp = [[10**4]*w for _ in range(h)]
for i,j in queue:
    dp[i][j] = 0
while len(queue):
    y,x = queue.popleft()
    d = dp[y][x]
    for dx,dy in dxy:
        nx, ny = x+dx, y+dy
        if not 0<=nx<=w-1:
            continue
        elif not 0<=ny<=h-1:
            continue
        elif dp[ny][nx]<=d+1:
            continue
        dp[ny][nx] = d+1
        queue.append((ny,nx))
print(max([max(dp[row]) for row in range(h)]))

Buggy python submission (verdict: Time Limit Exceeded):
h,w = map(int,input().split())
a = ['#'*(w+2)]+['#'+input()+'#' for _ in range(h)]+['#'*(w+2)]
ans = 0
while True:
    l = []
    for i in range(1,h+1):
        for j in range(1,w+1):
            if a[i][j]=='#':
                l.append([i,j])
    if len(l)==h*w:
        break
    ans += 1
    for l_ in l:
        a[l_[0]-1] = a[l_[0]-1][:l_[1]]+'#'+a[l_[0]-1][l_[1]+1:]
        a[l_[0]] = a[l_[0]][:l_[1]-1]+'###'+a[l_[0]][l_[1]+2:]
        a[l_[0]+1] = a[l_[0]+1][:l_[1]]+'#'+a[l_[0]+1][l_[1]+1:]
print(ans)

Fixed submission:
h,w = map(int,input().split())
a = [input() for _ in range(h)]
ans = 0
queue = []
for i in range(h):
    for j in range(w):
        if a[i][j]=='#':
            queue.append([i,j])
from collections import deque
queue = deque(queue)
dxy = [(0,1), (0,-1), (1,0), (-1,0)]
dp = [[10**4]*w for _ in range(h)]
for i,j in queue:
    dp[i][j] = 0
while len(queue):
    y,x = queue.popleft()
    d = dp[y][x]
    for dx,dy in dxy:
        nx, ny = x+dx, y+dy
        if not 0<=nx<=w-1:
            continue
        elif not 0<=ny<=h-1:
            continue
        elif dp[ny][nx]<=d+1:
            continue
        dp[ny][nx] = d+1
        queue.append((ny,nx))
print(max([max(dp[row]) for row in range(h)]))

Buggy python submission (verdict: Time Limit Exceeded):
h,w = map(int,input().split())
a = [input() for _ in range(h)]
ans = 0
dic = {}
for i in range(h):
    for j in range(w):
        if a[i][j]=='#':
            if not i in dic.keys():
                dic[i] = []
            dic[i].append(j)
ans = 0
for i in range(h):
    for j in range(w):
        if a[i][j]=='.':
            tmp = 10**4
            for key in dic.keys():
                for m in dic[key]:
                    tmp = min(tmp,abs(key-i)+abs(m-j))
            ans = max(ans,tmp)
print(ans)

Fixed submission:
h,w = map(int,input().split())
a = [input() for _ in range(h)]
ans = 0
queue = []
for i in range(h):
    for j in range(w):
        if a[i][j]=='#':
            queue.append([i,j])
from collections import deque
queue = deque(queue)
dxy = [(0,1), (0,-1), (1,0), (-1,0)]
dp = [[10**4]*w for _ in range(h)]
for i,j in queue:
    dp[i][j] = 0
while len(queue):
    y,x = queue.popleft()
    d = dp[y][x]
    for dx,dy in dxy:
        nx, ny = x+dx, y+dy
        if not 0<=nx<=w-1:
            continue
        elif not 0<=ny<=h-1:
            continue
        elif dp[ny][nx]<=d+1:
            continue
        dp[ny][nx] = d+1
        queue.append((ny,nx))
print(max([max(dp[row]) for row in range(h)]))

Buggy python submission (verdict: Time Limit Exceeded):
h,w = map(int,input().split())
a = ['*'*(w+2)]+['*'+input()+'*' for _ in range(h)]+['*'*(w+2)]
ans = 0
while True:
    k = 1
    l = []
    for i in range(1,h+1):
        for j in range(1,w+1):
            if a[i][j]=='.':
                k = 0
            if a[i][j-1]=='#' or a[i][j+1]=='#' or a[i+1][j]=='#' or a[i-1][j]=='#':
                l.append([i,j])
    for l_ in l:
        a[l_[0]]=a[l_[0]][:l_[1]]+'#'+a[l_[0]][l_[1]+1:]
    if k:
        break
    ans += 1
print(ans)

Fixed submission:
h,w = map(int,input().split())
a = [input() for _ in range(h)]
ans = 0
queue = []
for i in range(h):
    for j in range(w):
        if a[i][j]=='#':
            queue.append([i,j])
from collections import deque
queue = deque(queue)
dxy = [(0,1), (0,-1), (1,0), (-1,0)]
dp = [[10**4]*w for _ in range(h)]
for i,j in queue:
    dp[i][j] = 0
while len(queue):
    y,x = queue.popleft()
    d = dp[y][x]
    for dx,dy in dxy:
        nx, ny = x+dx, y+dy
        if not 0<=nx<=w-1:
            continue
        elif not 0<=ny<=h-1:
            continue
        elif dp[ny][nx]<=d+1:
            continue
        dp[ny][nx] = d+1
        queue.append((ny,nx))
print(max([max(dp[row]) for row in range(h)]))