Problem p03014 (python)

Fixed submission:
H,W=map(int,input().split())
S=[]
for i in range(H):
    S.append(input())

L = [[0 for i in range(W)] for j in range(H)]
R = [[0 for i in range(W)] for j in range(H)]
U = [[0 for i in range(W)] for j in range(H)]
D = [[0 for i in range(W)] for j in range(H)]

ans=0

for i in range(H):
    for j in range(W):
        if S[i][j]=='.':
            if j==0:
                L[i][j]=1
            else:
                L[i][j]=L[i][j-1]+1
        if S[i][-j-1]=='.':
            if j==0:
                R[i][-j-1]=1
            else:
                R[i][-j-1]=R[i][-j]+1
        if S[i][j]=='.':
            if i==0:
                U[i][j]=1
            else:
                U[i][j]=U[i-1][j]+1
        if S[-i-1][j]=='.':
            if i==0:
                D[-i-1][j]=1
            else:
                D[-i-1][j]=D[-i][j]+1
for i in range(H):
    for j in range(W):
        ans = max(ans,L[i][j]+R[i][j]+U[i][j]+D[i][j]-3)
print(ans)

Buggy submission (verdict: Runtime Error):
H,W=map(int,input().split())
S=[]
for i in range(H):
    S.append(input())

L = [[0 for i in range(W)] for j in range(W)]
R = [[0 for i in range(W)] for j in range(W)]
U = [[0 for i in range(W)] for j in range(W)]
D = [[0 for i in range(W)] for j in range(W)]

ans=0

for i in range(H):
    for j in range(W):
        if S[i][j]=='.':
            if j==0:
                L[i][j]=1
            else:
                L[i][j]=L[i][j-1]+1
        if S[i][-j-1]=='.':
            if j==0:
                R[i][-j-1]=1
            else:
                R[i][-j-1]=R[i][-j]+1
        if S[i][j]=='.':
            if i==0:
                U[i][j]=1
            else:
                U[i][j]=U[i-1][j]+1
        if S[-i-1][j]=='.':
            if i==0:
                D[-i-1][j]=1
            else:
                D[-i-1][j]=D[-i][j]+1
for i in range(H):
    for j in range(W):
        ans = max(ans,L[i][j]+R[i][j]+U[i][j]+D[i][j]-3)
print(ans)

Buggy submission (verdict: Runtime Error):
H,W=map(int,input().split())
S=[]
for i in range(H):
    S.append(input())

L = [[0 for i in range(W)] for j in range(W)]
R = [[0 for i in range(W)] for j in range(W)]
U = [[0 for i in range(W)] for j in range(W)]
D = [[0 for i in range(W)] for j in range(W)]

ans=0

for i in range(H):
    for j in range(W):
        if S[i][j]=='.':
            if j==0:
                L[i][j]=1
            else:
                L[i][j]=L[i][j-1]+1
        if S[i][-j-1]=='.':
            if j==0:
                R[i][-j-1]=1
            else:
                R[i][-j-1]=R[i][-j]+1
        if S[i][j]=='.':
            if i==0:
                U[i][j]=1
            else:
                U[i][j]=U[i-1][j]+1
        if S[-i-1][j]=='.':
            if i==0:
                D[-i-1][j]=1
            else:
                D[-i-1][j]=D[-i][j]+1
for i in range(H):
    for j in range(W):
        ans = max(ans,L[i][j]+R[i][j]+U[i][j]+D[i][j]-3)
print(ans)

Buggy submission (verdict: Runtime Error):
H,W=map(int,input().split())
S=[]
for i in range(H):
    S.append(input())

from collections import defaultdict


y = [[] for i in range(W)]
x=0
left=-1

ans=1

for i in range(H):
    left=-1
    for j in range(W):
        if S[i][j]=='.' and left==-1:
            left=j
        elif (S[i][j]=='#' and left!=-1) or j==W-1:
            if S[i][j]=='#':
                x=j-left
            else:
                x=j-left+1

            for k in range(left,left+x):
                if y[i][k]!=0:
                    ans=max(ans,x+y[i][k]-1)
                else:
                    l=i+1
                    while l<H and S[l][k]==".":
                        l+=1
                    y_val=l-i
                    ans = max(ans,x+y_val-1)
                    for m in range(i+1,l):
                        y[m][k]=y_val
            left=-1

print(ans)