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

h,w = map(int,input().split())
#a = [input() for _ in range(h)]
a = [list(input()) for _ in range(h)]
b = [[False]*w for _ in range(h)]
c = []
d = [(-1,0), (1,0), (0,-1), (0,1)]
ans = 0

for i in range(h):
    for j in range(w):
        if a[i][j] == '#':
            b[i][j] = True
            c.append((i,j))

while True:
    tmp = []
    cnt = 0
    for i,j in c:
        for d1,d2 in d:
            if 0 <= i + d1 < h and 0 <= j + d2 < w:
                if not b[i+d1][j+d2]:
                    tmp.append((i+d1, j+d2))
                    b[i+d1][j+d2] = True
                    cnt += 1
    if cnt > 0:
        c = copy.deepcopy(tmp)
        ans += 1
    else:
        break

print(ans)


Fixed submission:
import copy
#import time

h,w = map(int,input().split())
a = [input() for _ in range(h)]
b = [[False]*w for _ in range(h)]
#s = time.time()
c = []
d = [(-1,0), (1,0), (0,-1), (0,1)]
ans = 0

for i in range(h):
    for j in range(w):
        if a[i][j] == '#':
            b[i][j] = True
            c.append((i,j))
#print(time.time()-s)

while True:
    tmp = []
    cnt = 0
    for i,j in c:
        for d1,d2 in d:
            if 0 <= i + d1 < h and 0 <= j + d2 < w:
                if not b[i+d1][j+d2]:
                    tmp.append((i+d1, j+d2))
                    b[i+d1][j+d2] = True
                    cnt += 1
    #print(time.time()-s)
    if cnt > 0:
        c = copy.copy(tmp)
        ans += 1
    else:
        break
    #print(time.time()-s)

print(ans)

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

h,w = map(int,input().split())
#a = [input() for _ in range(h)]
a = [list(input()) for _ in range(h)]
#b = [[False]*w for _ in range(h)]
c = []
d = [(-1,0), (1,0), (0,-1), (0,1)]
ans = 0

"""
for i in range(h):
    for j in range(w):
        if a[i][j] == '#':
            b[i][j] = True
            c.append((i,j))
"""

for i in range(h):
    for j in range(w):
        if a[i][j] == '#':
            c.append((i,j))

while True:
    tmp = []
    cnt = 0
    for i,j in c:
        for d1,d2 in d:
            if 0 <= i + d1 < h and 0 <= j + d2 < w:
                #if not b[i+d1][j+d2]:
                if a[i+d1][j+d2] == '.':
                    tmp.append((i+d1, j+d2))
                    #b[i+d1][j+d2] = True
                    a[i+d1][j+d2] = '#'
                    cnt += 1
    if cnt > 0:
        c = copy.deepcopy(tmp)
        ans += 1
    else:
        break

print(ans)


Fixed submission:
import copy
#import time

h,w = map(int,input().split())
a = [input() for _ in range(h)]
b = [[False]*w for _ in range(h)]
#s = time.time()
c = []
d = [(-1,0), (1,0), (0,-1), (0,1)]
ans = 0

for i in range(h):
    for j in range(w):
        if a[i][j] == '#':
            b[i][j] = True
            c.append((i,j))
#print(time.time()-s)

while True:
    tmp = []
    cnt = 0
    for i,j in c:
        for d1,d2 in d:
            if 0 <= i + d1 < h and 0 <= j + d2 < w:
                if not b[i+d1][j+d2]:
                    tmp.append((i+d1, j+d2))
                    b[i+d1][j+d2] = True
                    cnt += 1
    #print(time.time()-s)
    if cnt > 0:
        c = copy.copy(tmp)
        ans += 1
    else:
        break
    #print(time.time()-s)

print(ans)

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

h,w = map(int,input().split())
a = [input() for _ in range(h)]
b = [[False]*w for _ in range(h)]
c = []
d = [(-1,0), (1,0), (0,-1), (0,1)]
ans = 0

for i in range(h):
    for j in range(w):
        if a[i][j] == '#':
            b[i][j] = True
            c.append((i,j))

while True:
    tmp = []
    cnt = 0
    for i,j in c:
        for d1,d2 in d:
            if 0 <= i + d1 < h and 0 <= j + d2 < w:
                if not b[i+d1][j+d2]:
                    tmp.append((i+d1, j+d2))
                    b[i+d1][j+d2] = True
                    cnt += 1
    if cnt > 0:
        c = copy.deepcopy(tmp)
        ans += 1
    else:
        break

print(ans)


Fixed submission:
import copy
#import time

h,w = map(int,input().split())
a = [input() for _ in range(h)]
b = [[False]*w for _ in range(h)]
#s = time.time()
c = []
d = [(-1,0), (1,0), (0,-1), (0,1)]
ans = 0

for i in range(h):
    for j in range(w):
        if a[i][j] == '#':
            b[i][j] = True
            c.append((i,j))
#print(time.time()-s)

while True:
    tmp = []
    cnt = 0
    for i,j in c:
        for d1,d2 in d:
            if 0 <= i + d1 < h and 0 <= j + d2 < w:
                if not b[i+d1][j+d2]:
                    tmp.append((i+d1, j+d2))
                    b[i+d1][j+d2] = True
                    cnt += 1
    #print(time.time()-s)
    if cnt > 0:
        c = copy.copy(tmp)
        ans += 1
    else:
        break
    #print(time.time()-s)

print(ans)

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

    h,w = map(int,input().split())
    a = [input() for _ in range(h)]
    b = [[False]*w for _ in range(h)]
    c = []
    d = [(-1,0), (1,0), (0,-1), (0,1)]
    ans = 0

    for i in range(h):
        for j in range(w):
            if a[i][j] == '#':
                b[i][j] = True
                c.append((i,j))

    while True:
        tmp = []
        for i,j in c:
            for d1,d2 in d:
                if 0 <= i + d1 < h and 0 <= j + d2 < w:
                    if not b[i+d1][j+d2]:
                        tmp.append((i+d1, j+d2))
                        b[i+d1][j+d2] = True
        if tmp:
            c = copy.deepcopy(tmp)
            ans += 1
        else:
            break

    print(ans)

if __name__ == '__main__':
    main()


Fixed submission:
import copy
#import time

h,w = map(int,input().split())
a = [input() for _ in range(h)]
b = [[False]*w for _ in range(h)]
#s = time.time()
c = []
d = [(-1,0), (1,0), (0,-1), (0,1)]
ans = 0

for i in range(h):
    for j in range(w):
        if a[i][j] == '#':
            b[i][j] = True
            c.append((i,j))
#print(time.time()-s)

while True:
    tmp = []
    cnt = 0
    for i,j in c:
        for d1,d2 in d:
            if 0 <= i + d1 < h and 0 <= j + d2 < w:
                if not b[i+d1][j+d2]:
                    tmp.append((i+d1, j+d2))
                    b[i+d1][j+d2] = True
                    cnt += 1
    #print(time.time()-s)
    if cnt > 0:
        c = copy.copy(tmp)
        ans += 1
    else:
        break
    #print(time.time()-s)

print(ans)

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

h,w = map(int,input().split())
a = [input() for _ in range(h)]
b = [[False]*w for _ in range(h)]
c = []
d = [(-1,0), (1,0), (0,-1), (0,1)]
ans = 0

for i in range(h):
    for j in range(w):
        if a[i][j] == '#':
            b[i][j] = True
            c.append((i,j))

while True:
    tmp = []
    for i,j in c:
        for d1,d2 in d:
            if 0 <= i + d1 < h and 0 <= j + d2 < w:
                if not b[i+d1][j+d2]:
                    tmp.append((i+d1, j+d2))
                    b[i+d1][j+d2] = True
    if tmp:
        c = copy.deepcopy(tmp)
        ans += 1
    else:
        break

print(ans)


Fixed submission:
import copy
#import time

h,w = map(int,input().split())
a = [input() for _ in range(h)]
b = [[False]*w for _ in range(h)]
#s = time.time()
c = []
d = [(-1,0), (1,0), (0,-1), (0,1)]
ans = 0

for i in range(h):
    for j in range(w):
        if a[i][j] == '#':
            b[i][j] = True
            c.append((i,j))
#print(time.time()-s)

while True:
    tmp = []
    cnt = 0
    for i,j in c:
        for d1,d2 in d:
            if 0 <= i + d1 < h and 0 <= j + d2 < w:
                if not b[i+d1][j+d2]:
                    tmp.append((i+d1, j+d2))
                    b[i+d1][j+d2] = True
                    cnt += 1
    #print(time.time()-s)
    if cnt > 0:
        c = copy.copy(tmp)
        ans += 1
    else:
        break
    #print(time.time()-s)

print(ans)

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

    r1 = [1,0,0,-1]
    r2 = [0,1,-1,0]
    q = []
    visits = [[False] * w for _ in range(h)]
    ans = 0

    for i in range(h):
        for j in range(w):
            if a[i][j] == '#':
                q.append((i, j))
                visits[i][j] = True

    while q:
        p = []
        for _ in range(len(q)):
            s,t = q.pop(0)
            for i in range(4):
                r10 = r1[i]
                r20 = r2[i]
                if 0 <= s + r10 < h and 0 <= t + r20 < w:
                    if not visits[s + r10][t + r20]:
                        visits[s + r10][t + r20] = True
                        p.append((s + r10,t + r20))
        q = p
        ans += 1

    print(ans-1)

if __name__ == '__main__':
    main()

Fixed submission:
import copy
#import time

h,w = map(int,input().split())
a = [input() for _ in range(h)]
b = [[False]*w for _ in range(h)]
#s = time.time()
c = []
d = [(-1,0), (1,0), (0,-1), (0,1)]
ans = 0

for i in range(h):
    for j in range(w):
        if a[i][j] == '#':
            b[i][j] = True
            c.append((i,j))
#print(time.time()-s)

while True:
    tmp = []
    cnt = 0
    for i,j in c:
        for d1,d2 in d:
            if 0 <= i + d1 < h and 0 <= j + d2 < w:
                if not b[i+d1][j+d2]:
                    tmp.append((i+d1, j+d2))
                    b[i+d1][j+d2] = True
                    cnt += 1
    #print(time.time()-s)
    if cnt > 0:
        c = copy.copy(tmp)
        ans += 1
    else:
        break
    #print(time.time()-s)

print(ans)

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

r1 = [1,0,0,-1]
r2 = [0,1,-1,0]
q = []
visits = [[False] * w for _ in range(h)]
ans = 0

for i in range(h):
    for j in range(w):
        if a[i][j] == '#':
            q.append((i, j))
            visits[i][j] = True

while q:
    p = []
    for _ in range(len(q)):
        s,t = q.pop(0)
        for i in range(4):
            r10 = r1[i]
            r20 = r2[i]
            if 0 <= s + r10 < h and 0 <= t + r20 < w:
                if not visits[s + r10][t + r20]:
                    visits[s + r10][t + r20] = True
                    p.append((s + r10,t + r20))
    q = p
    ans += 1

print(ans-1)


Fixed submission:
import copy
#import time

h,w = map(int,input().split())
a = [input() for _ in range(h)]
b = [[False]*w for _ in range(h)]
#s = time.time()
c = []
d = [(-1,0), (1,0), (0,-1), (0,1)]
ans = 0

for i in range(h):
    for j in range(w):
        if a[i][j] == '#':
            b[i][j] = True
            c.append((i,j))
#print(time.time()-s)

while True:
    tmp = []
    cnt = 0
    for i,j in c:
        for d1,d2 in d:
            if 0 <= i + d1 < h and 0 <= j + d2 < w:
                if not b[i+d1][j+d2]:
                    tmp.append((i+d1, j+d2))
                    b[i+d1][j+d2] = True
                    cnt += 1
    #print(time.time()-s)
    if cnt > 0:
        c = copy.copy(tmp)
        ans += 1
    else:
        break
    #print(time.time()-s)

print(ans)

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

r1 = [1,0,0,-1]
r2 = [0,1,-1,0]
q = []
dis = [[-1]*w for _ in range(h)]
ans = 0

for i in range(h):
    for j in range(w):
        if a[i][j] == '#':
            q.append(((i, j), 0))
            dis[i][j] = 0

while q:
    p,d = q.pop(0)
    for i in range(4):
        r1i = r1[i]
        r2i = r2[i]
        if 0 <= p[0] + r1i < h and 0 <= p[1] + r2i < w:
            if dis[p[0]+r1i][p[1]+r2i] == -1 or dis[p[0]+r1i][p[1]+r2i] > dis[p[0]][p[1]] + 1:
                q.append(((p[0]+r1i,p[1]+r2i), dis[p[0]][p[1]] + 1))
                dis[p[0]+r1i][p[1]+r2i] = dis[p[0]][p[1]] + 1

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

print(ans)


Fixed submission:
import copy
#import time

h,w = map(int,input().split())
a = [input() for _ in range(h)]
b = [[False]*w for _ in range(h)]
#s = time.time()
c = []
d = [(-1,0), (1,0), (0,-1), (0,1)]
ans = 0

for i in range(h):
    for j in range(w):
        if a[i][j] == '#':
            b[i][j] = True
            c.append((i,j))
#print(time.time()-s)

while True:
    tmp = []
    cnt = 0
    for i,j in c:
        for d1,d2 in d:
            if 0 <= i + d1 < h and 0 <= j + d2 < w:
                if not b[i+d1][j+d2]:
                    tmp.append((i+d1, j+d2))
                    b[i+d1][j+d2] = True
                    cnt += 1
    #print(time.time()-s)
    if cnt > 0:
        c = copy.copy(tmp)
        ans += 1
    else:
        break
    #print(time.time()-s)

print(ans)

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

for i in range(h):
    for j in range(w):
        if a[i][j] == '#':
            black.append([i,j])
        else:
            white.append([i,j])

for i in range(len(white)):
    min1 = 10**10
    for j in range(len(black)):
        min1 = min(min1,abs(black[j][0]-white[i][0])+abs(black[j][1]-white[i][1]))
        if min1 == 1:
            break
    ans = max(ans,min1)

print(ans)


Fixed submission:
import copy
#import time

h,w = map(int,input().split())
a = [input() for _ in range(h)]
b = [[False]*w for _ in range(h)]
#s = time.time()
c = []
d = [(-1,0), (1,0), (0,-1), (0,1)]
ans = 0

for i in range(h):
    for j in range(w):
        if a[i][j] == '#':
            b[i][j] = True
            c.append((i,j))
#print(time.time()-s)

while True:
    tmp = []
    cnt = 0
    for i,j in c:
        for d1,d2 in d:
            if 0 <= i + d1 < h and 0 <= j + d2 < w:
                if not b[i+d1][j+d2]:
                    tmp.append((i+d1, j+d2))
                    b[i+d1][j+d2] = True
                    cnt += 1
    #print(time.time()-s)
    if cnt > 0:
        c = copy.copy(tmp)
        ans += 1
    else:
        break
    #print(time.time()-s)

print(ans)

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

for i in range(h):
    for j in range(w):
        if a[i][j] == '#':
            black.append([i,j])
        else:
            white.append([i,j])

for i in range(len(white)):
    min1 = 10**10
    for j in range(len(black)):
        min1 = min(min1,abs(black[j][0]-white[i][0])+abs(black[j][1]-white[i][1]))
    ans = max(ans,min1)

print(ans)


Fixed submission:
import copy
#import time

h,w = map(int,input().split())
a = [input() for _ in range(h)]
b = [[False]*w for _ in range(h)]
#s = time.time()
c = []
d = [(-1,0), (1,0), (0,-1), (0,1)]
ans = 0

for i in range(h):
    for j in range(w):
        if a[i][j] == '#':
            b[i][j] = True
            c.append((i,j))
#print(time.time()-s)

while True:
    tmp = []
    cnt = 0
    for i,j in c:
        for d1,d2 in d:
            if 0 <= i + d1 < h and 0 <= j + d2 < w:
                if not b[i+d1][j+d2]:
                    tmp.append((i+d1, j+d2))
                    b[i+d1][j+d2] = True
                    cnt += 1
    #print(time.time()-s)
    if cnt > 0:
        c = copy.copy(tmp)
        ans += 1
    else:
        break
    #print(time.time()-s)

print(ans)