Buggy python submission (verdict: Time Limit Exceeded):
h,w=map(int,input().split())
s=set()
a=[]
from collections import deque
q=deque([])
for i in range(h):
    tmp=list(input())
    a.append(tmp)
    for j in range(w):
        if tmp[j]=="#":
            q.append((i,j,0))

ans=0
ll=[[0,1],[0,-1],[1,0],[-1,0]]
while q:
    x,y,v=q.popleft()
    ans=max(ans,v)
    for i,j in ll:
        if 0<=x+i<h and 0<=y+j<w and a[i+x][j+y]==".":
            a[i+x][j+y]="#"
            q.append((i+x,j+y,v+1))

print(ans)





Fixed submission:
h,w=map(int,input().split())
s=set()
a=[]
from collections import deque
q=deque([])
for i in range(h):
    tmp=list(input())
    a.append(tmp)
    for j in range(w):
        if tmp[j]=="#":
            q.append((i,j,0))

ans=0
ll=[[0,1],[0,-1],[1,0],[-1,0]]
while q:
    x,y,v=q.popleft()
    ans=max(ans,v)
    for i,j in ll:
        if 0<=x+i<h and 0<=y+j<w and a[i+x][j+y]==".":
            a[i+x][j+y]="#"
            q.append((i+x,j+y,v+1))

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
h,w=map(int,input().split())
s=set()
q=[]
for i in range(h):
    tmp=input()
    for j in range(w):
        if tmp[j]=="#":
            q.append((i,j))
            s.add((i,j))

ans=0
ll=[[0,1],[0,-1],[1,0],[-1,0]]
while q:
    l=[]
    for i,j in q:
        for x,y in ll:
            if i+x>=0 and i+x<h and j+y>=0 and j+y<w:
                if (i+x,j+y) not in s:
                    s.add((i+x,j+y))
                    l.append((i+x,j+y))
    q=l
    ans+=1

print(ans-1)





Fixed submission:
h,w=map(int,input().split())
s=set()
a=[]
from collections import deque
q=deque([])
for i in range(h):
    tmp=list(input())
    a.append(tmp)
    for j in range(w):
        if tmp[j]=="#":
            q.append((i,j,0))

ans=0
ll=[[0,1],[0,-1],[1,0],[-1,0]]
while q:
    x,y,v=q.popleft()
    ans=max(ans,v)
    for i,j in ll:
        if 0<=x+i<h and 0<=y+j<w and a[i+x][j+y]==".":
            a[i+x][j+y]="#"
            q.append((i+x,j+y,v+1))

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
h,w=map(int,input().split())
s=set()
from collections import deque
q=deque([])
for i in range(h):
    tmp=input()
    for j in range(w):
        if tmp[j]=="#":
            q.append((i,j))
            s.add((i,j))

ans=0
ll=[[0,1],[0,-1],[1,0],[-1,0]]
while q:
    l=[]
    while q:
        i,j=q.popleft()
        for x,y in ll:
            if i+x>=0 and i+x<h and j+y>=0 and j+y<w:
                if (i+x,j+y) not in s:
                    s.add((i+x,j+y))
                    l.append((i+x,j+y))
    q=deque(l)
    ans+=1

print(ans-1)





Fixed submission:
h,w=map(int,input().split())
s=set()
a=[]
from collections import deque
q=deque([])
for i in range(h):
    tmp=list(input())
    a.append(tmp)
    for j in range(w):
        if tmp[j]=="#":
            q.append((i,j,0))

ans=0
ll=[[0,1],[0,-1],[1,0],[-1,0]]
while q:
    x,y,v=q.popleft()
    ans=max(ans,v)
    for i,j in ll:
        if 0<=x+i<h and 0<=y+j<w and a[i+x][j+y]==".":
            a[i+x][j+y]="#"
            q.append((i+x,j+y,v+1))

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
h,w=map(int,input().split())
s=set()
from collections import deque
q=deque([])
for i in range(h):
    tmp=input()
    for j in range(w):
        if tmp[j]=="#":
            q.append((i,j))
            s.add((i,j))

ans=0
ll=[[0,1],[0,-1],[1,0],[-1,0]]
while q:
    l=[]
    while q:
        i,j=q.popleft()
        for x,y in ll:
            if i+x>=0 and i+x<h and j+y>=0 and j+y<w:
                if (i+x,j+y) not in s:
                    s.add((i+x,j+y))
                    l.append((i+x,j+y))
    q=deque(l)
    ans+=1

print(ans-1)





Fixed submission:
h,w=map(int,input().split())
s=set()
a=[]
from collections import deque
q=deque([])
for i in range(h):
    tmp=list(input())
    a.append(tmp)
    for j in range(w):
        if tmp[j]=="#":
            q.append((i,j,0))

ans=0
ll=[[0,1],[0,-1],[1,0],[-1,0]]
while q:
    x,y,v=q.popleft()
    ans=max(ans,v)
    for i,j in ll:
        if 0<=x+i<h and 0<=y+j<w and a[i+x][j+y]==".":
            a[i+x][j+y]="#"
            q.append((i+x,j+y,v+1))

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
h,w=map(int,input().split())
a=[]
ans=0
s=set()
from collections import deque
q=deque([])
l=[[10**10 for i in range(w)]for j in range(h)]
for i in range(h):
    p=input()
    a.append(p)
    for j in range(w):
        if p[j]=="#":
            q.append((i,j))
            l[i][j]=0
        else:
            s.add((i,j))

while s:
    i,j=q.popleft()
    if (i-1,j) in s:
        s.remove((i-1,j))
        q.append((i-1,j))
        l[i-1][j]=l[i][j]+1
        ans=max(ans,l[i][j]+1)
    if (i+1,j) in s:
        s.remove((i+1,j))
        q.append((i+1,j))
        l[i+1][j]=l[i][j]+1
        ans=max(ans,l[i][j]+1)
    if (i,j-1) in s:
        s.remove((i,j-1))
        q.append((i,j-1))
        l[i][j-1]=l[i][j]+1
        ans=max(ans,l[i][j]+1)
    if (i,j+1) in s:
        s.remove((i,j+1))
        q.append((i,j+1))
        l[i][j+1]=l[i][j]+1
        ans=max(ans,l[i][j]+1)
    
print(ans)      






Fixed submission:
h,w=map(int,input().split())
s=set()
a=[]
from collections import deque
q=deque([])
for i in range(h):
    tmp=list(input())
    a.append(tmp)
    for j in range(w):
        if tmp[j]=="#":
            q.append((i,j,0))

ans=0
ll=[[0,1],[0,-1],[1,0],[-1,0]]
while q:
    x,y,v=q.popleft()
    ans=max(ans,v)
    for i,j in ll:
        if 0<=x+i<h and 0<=y+j<w and a[i+x][j+y]==".":
            a[i+x][j+y]="#"
            q.append((i+x,j+y,v+1))

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
h,w=map(int,input().split())
a=[]
s=set()
from collections import deque
q=deque([])
l=[[10**10 for i in range(w)]for j in range(h)]
for i in range(h):
    p=input()
    a.append(p)
    for j in range(w):
        if p[j]=="#":
            q.append((i,j))
            l[i][j]=0
        else:
            s.add((i,j))

while s:
    i,j=q.popleft()
    if (i-1,j) in s:
        s.remove((i-1,j))
        q.append((i-1,j))
        l[i-1][j]=min(l[i-1][j],l[i][j]+1)
    if (i+1,j) in s:
        s.remove((i+1,j))
        q.append((i+1,j))
        l[i+1][j]=min(l[i+1][j],l[i][j]+1)
    if (i,j-1) in s:
        s.remove((i,j-1))
        q.append((i,j-1))
        l[i][j-1]=min(l[i][j-1],l[i][j]+1)
    if (i,j+1) in s:
        s.remove((i,j+1))
        q.append((i,j+1))
        l[i][j+1]=min(l[i][j+1],l[i][j]+1)
ans=0
for i in range(h):
    for j in range(w):
        ans=max(ans,l[i][j])
print(ans)      






Fixed submission:
h,w=map(int,input().split())
s=set()
a=[]
from collections import deque
q=deque([])
for i in range(h):
    tmp=list(input())
    a.append(tmp)
    for j in range(w):
        if tmp[j]=="#":
            q.append((i,j,0))

ans=0
ll=[[0,1],[0,-1],[1,0],[-1,0]]
while q:
    x,y,v=q.popleft()
    ans=max(ans,v)
    for i,j in ll:
        if 0<=x+i<h and 0<=y+j<w and a[i+x][j+y]==".":
            a[i+x][j+y]="#"
            q.append((i+x,j+y,v+1))

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
h,w=map(int,input().split())
a=[]
s=set()
from collections import deque
q=deque([])
l=[[10**10 for i in range(w)]for j in range(h)]
for i in range(h):
    p=input()
    a.append(p)
    for j in range(w):
        if p[j]=="#":
            q.append((i,j))
            l[i][j]=0
        else:
            s.add((i,j))

while s:
    i,j=q.popleft()
    if (i-1,j) in s:
        s.remove((i-1,j))
        q.append((i-1,j))
        l[i-1][j]=min(l[i-1][j],l[i][j]+1)
    if (i+1,j) in s:
        s.remove((i+1,j))
        q.append((i+1,j))
        l[i+1][j]=min(l[i+1][j],l[i][j]+1)
    if (i,j-1) in s:
        s.remove((i,j-1))
        q.append((i,j-1))
        l[i][j-1]=min(l[i][j-1],l[i][j]+1)
    if (i,j+1) in s:
        s.remove((i,j+1))
        q.append((i,j+1))
        l[i][j+1]=min(l[i][j+1],l[i][j]+1)
ans=0
for i in range(h):
    for j in range(w):
        ans=max(ans,l[i][j])
print(ans)      






Fixed submission:
h,w=map(int,input().split())
s=set()
a=[]
from collections import deque
q=deque([])
for i in range(h):
    tmp=list(input())
    a.append(tmp)
    for j in range(w):
        if tmp[j]=="#":
            q.append((i,j,0))

ans=0
ll=[[0,1],[0,-1],[1,0],[-1,0]]
while q:
    x,y,v=q.popleft()
    ans=max(ans,v)
    for i,j in ll:
        if 0<=x+i<h and 0<=y+j<w and a[i+x][j+y]==".":
            a[i+x][j+y]="#"
            q.append((i+x,j+y,v+1))

print(ans)