Problem p03053 (python)

Fixed submission:
import sys,math,collections,itertools,copy
input = sys.stdin.readline

H,W=list(map(int,input().split()))
s = []
dot_cnt = 0
for _ in range(H):
    a = input().rstrip()
    dot_cnt += a.count('.')
    s.append(list(a))

num_lis = [[float('inf')]*W for _ in range(H)]

#--#
for ih in range(H):
    for iw in range(W):
        if s[ih][iw]=='#':
            num_lis[ih][iw]=0
        else:
            if iw-1>=0:
                num_lis[ih][iw] = min(num_lis[ih][iw-1]+1,num_lis[ih][iw])
                
    for iw in range(W-1,-1,-1):
        
        if s[ih][iw]=='#':
            num_lis[ih][iw]=0
        else:
            if iw+1<=W-1:
                num_lis[ih][iw] = min(num_lis[ih][iw+1]+1,num_lis[ih][iw])

#--#
for iw in range(W):
    for ih in range(H):
        if s[ih][iw]=='#':
            num_lis[ih][iw]=0
        else:
            if ih-1>=0:
                num_lis[ih][iw] = min(num_lis[ih-1][iw]+1,num_lis[ih][iw])
                
    for ih in range(H-1,-1,-1):
        if s[ih][iw]=='#':
            num_lis[ih][iw]=0
        else:
            if ih+1<=H-1:
                num_lis[ih][iw] = min(num_lis[ih+1][iw]+1,num_lis[ih][iw])

maxOpe = 0
for iw in range(W):
    for ih in range(H):
        maxOpe = max(maxOpe,num_lis[ih][iw])
print(maxOpe)

Buggy submission (verdict: Runtime Error):
import sys,math,collections,itertools,copy
input = sys.stdin.readline

H,W=list(map(int,input().split()))
s = []
dot_cnt = 0
for _ in range(W):
    a = input().rstrip()
    dot_cnt += a.count('.')
    s.append(list(a))

numOpe = 0
while dot_cnt:
    numOpe += 1
    tmp = copy.deepcopy(s)
    for ih in range(H):
        for iw in range(W):
            if s[ih][iw]=='#':
                if (ih+1 != H) and (s[ih+1][iw]!='#')and(tmp[ih+1][iw]!='#'):
                    tmp[ih+1][iw]='#'
                    dot_cnt -=1
                elif(ih-1 != -1) and (s[ih-1][iw]!='#')and(tmp[ih-1][iw]!='#'):
                    tmp[ih-1][iw]='#'
                    dot_cnt -=1
                elif(iw+1 != W) and (s[ih][iw+1]!='#')and( tmp[ih][iw+1]!='#'):
                    tmp[ih][iw+1]='#'
                    dot_cnt -=1
                elif(iw-1 != -1) and (s[ih][iw-1]!='#')and(tmp[ih][iw-1]!='#'):
                    tmp[ih][iw-1]='#'
                    dot_cnt -=1        

    s = copy.deepcopy(tmp)
print(numOpe)

Buggy submission (verdict: Runtime Error):
import sys,math,collections,itertools,copy
input = sys.stdin.readline

H,W=list(map(int,input().split()))
s = []
dot_cnt = 0
for _ in range(W):
    a = input().rstrip()
    dot_cnt += a.count('.')
    s.append(list(a))

numOpe = 0
while dot_cnt:
    numOpe += 1
    tmp = copy.deepcopy(s)
    for ih in range(H):
        for iw in range(W):
            if s[ih][iw]=='#':
                if (ih+1 != H) and (s[ih+1][iw]!='#')and(tmp[ih+1][iw]!='#'):
                    tmp[ih+1][iw]='#'
                    dot_cnt -=1
                elif(ih-1 != -1) and (s[ih-1][iw]!='#')and(tmp[ih-1][iw]!='#'):
                    tmp[ih-1][iw]='#'
                    dot_cnt -=1
                elif(iw+1 != W) and (s[ih][iw+1]!='#')and( tmp[ih][iw+1]!='#'):
                    tmp[ih][iw+1]='#'
                    dot_cnt -=1
                elif(iw-1 != -1) and (s[ih][iw-1]!='#')and(tmp[ih][iw-1]!='#'):
                    tmp[ih][iw-1]='#'
                    dot_cnt -=1        

    s = copy.deepcopy(tmp)
print(numOpe)

Buggy submission (verdict: Runtime Error):
import sys,math,collections,itertools,copy
input = sys.stdin.readline

H,W=list(map(int,input().split()))
s = []
dot_cnt = 0
for _ in range(W):
    a = input().rstrip()
    dot_cnt += a.count('.')
    s.append(list(a))

numOpe = 0
while dot_cnt:
    numOpe += 1
    tmp = copy.deepcopy(s)
    for ih in range(H):
        for iw in range(W):
            if s[ih][iw] == '#':
                tmp[max(0,ih-1)][iw] = '#'
                tmp[min(ih+1,H-1)][iw] = '#'
                tmp[ih][max(0,iw-1)] = '#'
                tmp[ih][min(iw+1,W-1)] = '#'
    s = copy.deepcopy(tmp)
    dot_cnt=0
    for si in s:
        for sj in si:
            if sj =='.':
                dot_cnt = 1
                break
        if dot_cnt ==1:
            break
print(numOpe)