Buggy python submission (verdict: Time Limit Exceeded):
h,w = map(int, input().split())
a = ["#"+input()+"#" for _ in range(h)]
s = "#"*(w+2)
a = [s] + a + [s]


ds = [[0] + [-1]*w + [0] for _ in range(h)]
ds = [[0]*(w+2)] + ds + [[0]*(w+2)]

vectors = [(-1,0),(1,0),(0,-1),(0,1)]

stack = []

ans = 0

for i in range(1,h+1):
    for j in range(1,w+1):
        if a[i][j] == "#":
            stack.append((i,j))
            ds[i][j] = 0

while stack:
    nh,nw = stack.pop(0)
    for vh,vw in vectors:
        if ds[nh+vh][nw+vw] == -1:
            stack.append((nh+vh,nw+vw))
            ds[nh+vh][nw+vw] = ds[nh][nw] + 1
            ans = ds[nh][nw] + 1

print(ans)


Fixed submission:
import numpy as np
import copy

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

a = np.array([[0 if (ai[j] == "#") else np.inf for j in range(w)] for ai in a])

for i in range(1, h):
    a[i] = np.minimum(a[i], a[i - 1] + 1)
for i in range(h - 2, -1, -1):
    a[i] = np.minimum(a[i], a[i + 1] + 1)
for i in range(1, w):
    a[:, i] = np.minimum(a[:, i], a[:, i - 1] + 1)
for i in range(w - 2, -1, -1):
    a[:, i] = np.minimum(a[:, i], a[:, i + 1] + 1)

print(int(a.max()))

Buggy python submission (verdict: Time Limit Exceeded):
h,w = map(int, input().split())
a = ["#"+input()+"#" for _ in range(h)]
s = "#"*(w+2)
a = [s] + a + [s]


ds = [[0] + [-1]*w + [0] for _ in range(h)]
ds = [[0]*(w+2)] + ds + [[0]*(w+2)]

vectors = [(-1,0),(1,0),(0,-1),(0,1)]

stack = []

ans = 0

for i in range(1,h+1):
    for j in range(1,w+1):
        if a[i][j] == "#":
            stack.append((i,j))
            ds[i][j] = 0

while stack:
    nh,nw = stack.pop(0)
    for vh,vw in vectors:
        if ds[nh+vh][nw+vw] == -1:
            stack.append((nh+vh,nw+vw))
            ds[nh+vh][nw+vw] = ds[nh][nw] + 1
            ans = ds[nh][nw] + 1

print(ans)


Fixed submission:
import numpy as np
import copy

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

a = np.array([[0 if (ai[j] == "#") else np.inf for j in range(w)] for ai in a])

for i in range(1, h):
    a[i] = np.minimum(a[i], a[i - 1] + 1)
for i in range(h - 2, -1, -1):
    a[i] = np.minimum(a[i], a[i + 1] + 1)
for i in range(1, w):
    a[:, i] = np.minimum(a[:, i], a[:, i - 1] + 1)
for i in range(w - 2, -1, -1):
    a[:, i] = np.minimum(a[:, i], a[:, i + 1] + 1)

print(int(a.max()))

Buggy python submission (verdict: Time Limit Exceeded):
h,w = map(int, input().split())
a = ["#"+input()+"#" for _ in range(h)]
s = "#"*(w+2)
a = [s] + a + [s]


ds = [[0] + [-1]*w + [0] for _ in range(h)]
ds = [[0]*(w+2)] + ds + [[0]*(w+2)]

vectors = set([(-1,0),(1,0),(0,-1),(0,1)])

stack = []

ans = 0

for i in range(1,h+1):
    for j in range(1,w+1):
        if a[i][j] == "#":
            stack.append((i,j))
            ds[i][j] = 0

while stack:
    nh,nw = stack.pop(0)
    for vh,vw in vectors:
        if ds[nh+vh][nw+vw] == -1:
            stack.append((nh+vh,nw+vw))
            ds[nh+vh][nw+vw] = ds[nh][nw] + 1
            ans = ds[nh][nw] + 1

print(ans)


Fixed submission:
import numpy as np
import copy

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

a = np.array([[0 if (ai[j] == "#") else np.inf for j in range(w)] for ai in a])

for i in range(1, h):
    a[i] = np.minimum(a[i], a[i - 1] + 1)
for i in range(h - 2, -1, -1):
    a[i] = np.minimum(a[i], a[i + 1] + 1)
for i in range(1, w):
    a[:, i] = np.minimum(a[:, i], a[:, i - 1] + 1)
for i in range(w - 2, -1, -1):
    a[:, i] = np.minimum(a[:, i], a[:, i + 1] + 1)

print(int(a.max()))

Buggy python submission (verdict: Time Limit Exceeded):
h,w = map(int, input().split())
a = ["#"+input()+"#" for _ in range(h)]
s = "#"*(w+2)
a = [s] + a + [s]


ds = [[0] + [-1]*w + [0] for _ in range(h)]
ds = [[0]*(w+2)] + ds + [[0]*(w+2)]

vectors = set([(-1,0),(1,0),(0,-1),(0,1)])

stack = []

ans = 0

for i in range(1,h+1):
    for j in range(1,w+1):
        if a[i][j] == "#":
            stack.append((i,j))
            ds[i][j] = 0

while stack:
    nh,nw = stack.pop(0)
    for vh,vw in vectors:
        if ds[nh+vh][nw+vw] == -1:
            stack.append((nh+vh,nw+vw))
            ds[nh+vh][nw+vw] = ds[nh][nw] + 1
            ans = ds[nh][nw] + 1

print(ans)


Fixed submission:
import numpy as np
import copy

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

a = np.array([[0 if (ai[j] == "#") else np.inf for j in range(w)] for ai in a])

for i in range(1, h):
    a[i] = np.minimum(a[i], a[i - 1] + 1)
for i in range(h - 2, -1, -1):
    a[i] = np.minimum(a[i], a[i + 1] + 1)
for i in range(1, w):
    a[:, i] = np.minimum(a[:, i], a[:, i - 1] + 1)
for i in range(w - 2, -1, -1):
    a[:, i] = np.minimum(a[:, i], a[:, i + 1] + 1)

print(int(a.max()))

Buggy python submission (verdict: Time Limit Exceeded):
h,w = map(int, input().split())
a = [list(input()) for _ in range(h)]

ds = [[-1]*w for _ in range(h)]

vectors = set([(-1,0),(1,0),(0,-1),(0,1)])

stack = []

ans = 0

for i in range(h):
    for j in range(w):
        if a[i][j] == "#":
            stack.append((i,j))
            ds[i][j] = 0

while stack:
    nh,nw = stack.pop(0)
    for vh,vw in vectors:
        if nh+vh>=0 and nh+vh<h and nw+vw>=0 and nw+vw<w:
            if ds[nh+vh][nw+vw] == -1:
                stack.append((nh+vh,nw+vw))
                ds[nh+vh][nw+vw] = ds[nh][nw] + 1
                ans = ds[nh][nw] + 1

print(ans)


Fixed submission:
import numpy as np
import copy

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

a = np.array([[0 if (ai[j] == "#") else np.inf for j in range(w)] for ai in a])

for i in range(1, h):
    a[i] = np.minimum(a[i], a[i - 1] + 1)
for i in range(h - 2, -1, -1):
    a[i] = np.minimum(a[i], a[i + 1] + 1)
for i in range(1, w):
    a[:, i] = np.minimum(a[:, i], a[:, i - 1] + 1)
for i in range(w - 2, -1, -1):
    a[:, i] = np.minimum(a[:, i], a[:, i + 1] + 1)

print(int(a.max()))

Buggy python submission (verdict: Time Limit Exceeded):
h,w = map(int, input().split())
a = [list(input()) for _ in range(h)]

ds = [[-1]*w for _ in range(h)]

vectors = set([(-1,0),(1,0),(0,-1),(0,1)])

stack = []

ans = 0

for i in range(h):
    for j in range(w):
        if a[i][j] == "#":
            stack.append((i,j))
            ds[i][j] = 0

while stack:
    nh,nw = stack.pop(0)
    for vh,vw in vectors:
        if nh+vh>=0 and nh+vh<h and nw+vw>=0 and nw+vw<w:
            if ds[nh+vh][nw+vw] == -1:
                stack.append((nh+vh,nw+vw))
                ds[nh+vh][nw+vw] = ds[nh][nw] + 1
                ans = ds[nh][nw] + 1

print(ans)


Fixed submission:
import numpy as np
import copy

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

a = np.array([[0 if (ai[j] == "#") else np.inf for j in range(w)] for ai in a])

for i in range(1, h):
    a[i] = np.minimum(a[i], a[i - 1] + 1)
for i in range(h - 2, -1, -1):
    a[i] = np.minimum(a[i], a[i + 1] + 1)
for i in range(1, w):
    a[:, i] = np.minimum(a[:, i], a[:, i - 1] + 1)
for i in range(w - 2, -1, -1):
    a[:, i] = np.minimum(a[:, i], a[:, i + 1] + 1)

print(int(a.max()))

Buggy python submission (verdict: Time Limit Exceeded):
h,w = map(int, input().split())
a = [list(input()) for _ in range(h)]

ds = [[-1]*w for _ in range(h)]

vectors = [(-1,0),(1,0),(0,-1),(0,1)]

stack = []

ans = 0

visited = [[False]*w for _ in range(h)]

for i in range(h):
    for j in range(w):
        if a[i][j] == "#":
            stack.append((i,j))
            ds[i][j] = 0

while stack:
    nh,nw = stack.pop(0)
    for vh,vw in vectors:
        if nh+vh>=0 and nh+vh<h and nw+vw>=0 and nw+vw<w:
            if ds[nh+vh][nw+vw] == -1:
                stack.append((nh+vh,nw+vw))
                ds[nh+vh][nw+vw] = ds[nh][nw] + 1
                ans = ds[nh][nw] + 1

print(ans)


Fixed submission:
import numpy as np
import copy

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

a = np.array([[0 if (ai[j] == "#") else np.inf for j in range(w)] for ai in a])

for i in range(1, h):
    a[i] = np.minimum(a[i], a[i - 1] + 1)
for i in range(h - 2, -1, -1):
    a[i] = np.minimum(a[i], a[i + 1] + 1)
for i in range(1, w):
    a[:, i] = np.minimum(a[:, i], a[:, i - 1] + 1)
for i in range(w - 2, -1, -1):
    a[:, i] = np.minimum(a[:, i], a[:, i + 1] + 1)

print(int(a.max()))

Buggy python submission (verdict: Time Limit Exceeded):
h,w = map(int, input().split())
a = [list(input()) for _ in range(h)]

ds = [[-1]*w for _ in range(h)]

vectors = [(-1,0),(1,0),(0,-1),(0,1)]

stack = []

ans = 0

visited = [[False]*w for _ in range(h)]

for i in range(h):
    for j in range(w):
        if a[i][j] == "#":
            stack.append((i,j))
            ds[i][j] = 0

while stack:
    nh,nw = stack.pop(0)
    for vh,vw in vectors:
        if nh+vh>=0 and nh+vh<h and nw+vw>=0 and nw+vw<w:
            if ds[nh+vh][nw+vw] == -1:
                stack.append((nh+vh,nw+vw))
                ds[nh+vh][nw+vw] = ds[nh][nw] + 1
                ans = ds[nh][nw] + 1

print(ans)


Fixed submission:
import numpy as np
import copy

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

a = np.array([[0 if (ai[j] == "#") else np.inf for j in range(w)] for ai in a])

for i in range(1, h):
    a[i] = np.minimum(a[i], a[i - 1] + 1)
for i in range(h - 2, -1, -1):
    a[i] = np.minimum(a[i], a[i + 1] + 1)
for i in range(1, w):
    a[:, i] = np.minimum(a[:, i], a[:, i - 1] + 1)
for i in range(w - 2, -1, -1):
    a[:, i] = np.minimum(a[:, i], a[:, i + 1] + 1)

print(int(a.max()))

Buggy python submission (verdict: Time Limit Exceeded):
import collections as cl

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

ds = [[-1]*w for _ in range(h)]

vectors = [(-1,0),(1,0),(0,-1),(0,1)]

stack = cl.deque([])

ans = 0

visited = [[False]*w for _ in range(h)]

for i in range(h):
    for j in range(w):
        if a[i][j] == "#":
            stack.appendleft((i,j))
            ds[i][j] = 0

while stack:
    nh,nw = stack.pop()
    for vh,vw in vectors:
        if nh+vh>=0 and nh+vh<h and nw+vw>=0 and nw+vw<w:
            if ds[nh+vh][nw+vw] == -1:
                stack.appendleft((nh+vh,nw+vw))
                ds[nh+vh][nw+vw] = ds[nh][nw] + 1
                ans = ds[nh][nw] + 1

print(ans)


Fixed submission:
import numpy as np
import copy

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

a = np.array([[0 if (ai[j] == "#") else np.inf for j in range(w)] for ai in a])

for i in range(1, h):
    a[i] = np.minimum(a[i], a[i - 1] + 1)
for i in range(h - 2, -1, -1):
    a[i] = np.minimum(a[i], a[i + 1] + 1)
for i in range(1, w):
    a[:, i] = np.minimum(a[:, i], a[:, i - 1] + 1)
for i in range(w - 2, -1, -1):
    a[:, i] = np.minimum(a[:, i], a[:, i + 1] + 1)

print(int(a.max()))

Buggy python submission (verdict: Time Limit Exceeded):
import copy

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

acol = ["."]*(h+2)
acol[0] = ["."]*(w+2)
acol[h+1] = ["."]*(w+2)
arow = ["."]*(w)
count = 0
flag = 1

for i in range(h):
    ac = input()

    for j in range(w):
        arow[j] = ac[j]

    acol[i+1] = ["."] + arow + ["."]

while flag != 0:
    flag = 0
    acolaf = copy.deepcopy(acol)

    for i in range(h):

        for j in range(w):

            if acol[i+1][j+1] != "#":
                
                if acol[i+1][j] == "#" or acol[i][j+1] == "#" or acol[i+2][j+1] == "#" or acol[i+1][j+2] == "#":
                    acolaf[i+1][j+1] = "#"
                    flag += 1
        
    if flag > 0:
        count += 1
    
    acol = acolaf
            
print(count)

Fixed submission:
import numpy as np
import copy

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

a = np.array([[0 if (ai[j] == "#") else np.inf for j in range(w)] for ai in a])

for i in range(1, h):
    a[i] = np.minimum(a[i], a[i - 1] + 1)
for i in range(h - 2, -1, -1):
    a[i] = np.minimum(a[i], a[i + 1] + 1)
for i in range(1, w):
    a[:, i] = np.minimum(a[:, i], a[:, i - 1] + 1)
for i in range(w - 2, -1, -1):
    a[:, i] = np.minimum(a[:, i], a[:, i + 1] + 1)

print(int(a.max()))