Problem p03014 (python)

Fixed submission:
H,W = map(int,input().split())
G=[input() for _ in range(H)]
A_u=[[0 for _ in range(W)] for _ in range(H)]
A_d=[[0 for _ in range(W)] for _ in range(H)]
A_r=[[0 for _ in range(W)] for _ in range(H)]
A_l=[[0 for _ in range(W)] for _ in range(H)]
for h in range(H):
  for w in range(1,W):
    if G[h][w-1] == '.':
      A_r[h][w] = A_r[h][w-1]+1
  for w in range(W-2,-1,-1):
    if G[h][w+1] == '.':
      A_l[h][w] = A_l[h][w+1]+1
for w in range(W):
  for h in range(1,H):
    if G[h-1][w] == '.':
      A_d[h][w] = A_d[h-1][w]+1
  for h in range(H-2,-1,-1):
    if G[h+1][w] == '.':
      A_u[h][w] = A_u[h+1][w]+1
ans=0
for h in range(H):
  for w in range(W):
    if G[h][w] == '.':
      ans = max(ans,A_r[h][w]+A_l[h][w]+A_d[h][w]+A_u[h][w]+1)
print(ans)

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

U=[[-1]*W for _ in range(H)]
D=[[-1]*W for _ in range(H)]
L=[[-1]*W for _ in range(H)]
R=[[-1]*W for _ in range(H)]

def u(i,j):
    if U[i][j]==-1:
        if S[i][j]=='#':
            U[i][j]==-2
        elif i==0:
            U[i][j]=0
        elif U[i-1][j]==-1:
            u(i-1,j)
            if U[i-1][j]==-2:
                U[i][j]=0
            else:
                U[i][j]=U[i-1][j]+1
        elif U[i-1][j]==-2:
            U[i][j]=0
        else:
            U[i][j]=U[i-1][j]+1

def d(i,j):
    if D[i][j]==-1:
        if S[i][j]=='#':
            D[i][j]==-2
        elif i==H-1:
            D[i][j]=0
        elif D[i+1][j]==-1:
            d(i+1,j)
            if D[i+1][j]==-2:
                D[i][j]=0
            else:
                D[i][j]=D[i+1][j]+1
        elif D[i+1][j]==-2:
            D[i][j]=0
        else:
            D[i][j]=D[i+1][j]+1

def l(i,j):
    if L[i][j]==-1:
        if S[i][j]=='#':
            L[i][j]==-2
        elif j==0:
            L[i][j]=0
        elif L[i][j-1]==-1:
            l(i,j-1)
            if L[i][j-1]==-2:
                L[i][j]=0
            else:
                L[i][j]=L[i][j-1]+1
        elif L[i][j-1]==-2:
            L[i][j]=0
        else:
            L[i][j]=L[i][j-1]+1

def r(i,j):
    if R[i][j]==-1:
        if S[i][j]=='#':
            R[i][j]==-2
        elif j==W-1:
            R[i][j]=0
        elif R[i][j+1]==-1:
            r(i,j+1)
            if R[i][j+1]==-2:
                R[i][j]=0
            else:
                R[i][j]=R[i][j+1]+1
        elif R[i][j+1]==-2:
            R[i][j]=0
        else:
            R[i][j]=R[i][j+1]+1

def udlr(i,j):
    if S[i][j]=='#':
        U[i][j]=D[i][j]=L[i][j]=R[i][j]=-2
        return 0
    else:
        u(i,j);d(i,j);l(i,j);r(i,j);
        return U[i][j]+D[i][j]+L[i][j]+R[i][j]+1

x=0
for i in range(H):
    for j in range(W):
        x=max(x,max(x,udlr(i,j)))
print(x)

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

U=[[-1]*W for _ in range(H)]
D=[[-1]*W for _ in range(H)]
L=[[-1]*W for _ in range(H)]
R=[[-1]*W for _ in range(H)]

def u(i,j):
    if U[i][j]==-1:
        if S[i][j]=='#':
            U[i][j]==-2
        elif i==0:
            U[i][j]=0
        elif U[i-1][j]==-1:
            u(i-1,j)
            if U[i-1][j]==-2:
                U[i][j]=0
            else:
                U[i][j]=U[i-1][j]+1
        elif U[i-1][j]==-2:
            U[i][j]=0
        else:
            U[i][j]=U[i-1][j]+1

def d(i,j):
    if D[i][j]==-1:
        if S[i][j]=='#':
            D[i][j]==-2
        elif i==H-1:
            D[i][j]=0
        elif D[i+1][j]==-1:
            d(i+1,j)
            if D[i+1][j]==-2:
                D[i][j]=0
            else:
                D[i][j]=D[i+1][j]+1
        elif D[i+1][j]==-2:
            D[i][j]=0
        else:
            D[i][j]=D[i+1][j]+1

def l(i,j):
    if L[i][j]==-1:
        if S[i][j]=='#':
            L[i][j]==-2
        elif j==0:
            L[i][j]=0
        elif L[i][j-1]==-1:
            l(i,j-1)
            if L[i][j-1]==-2:
                L[i][j]=0
            else:
                L[i][j]=L[i][j-1]+1
        elif L[i][j-1]==-2:
            L[i][j]=0
        else:
            L[i][j]=L[i][j-1]+1

def r(i,j):
    if R[i][j]==-1:
        if S[i][j]=='#':
            R[i][j]==-2
        elif j==W-1:
            R[i][j]=0
        elif R[i][j+1]==-1:
            r(i,j+1)
            if R[i][j+1]==-2:
                R[i][j]=0
            else:
                R[i][j]=R[i][j+1]+1
        elif R[i][j+1]==-2:
            R[i][j]=0
        else:
            R[i][j]=R[i][j+1]+1

def udlr(i,j):
    if S[i][j]=='#':
        U[i][j]=D[i][j]=L[i][j]=R[i][j]=-2
        return 0
    else:
        if U[i][j]==-1:
            u(i,j)
        if D[i][j]==-1:
            d(i,j)
        if L[i][j]==-1:
            l(i,j)
        if R[i][j]==-1:
            r(i,j)
        return U[i][j]+D[i][j]+L[i][j]+R[i][j]+1

x=0
for i in range(H):
    for j in range(W):
        x=max(x,max(x,udlr(i,j)))
print(x)

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

U=[[-1]*W for _ in range(H)]
D=[[-1]*W for _ in range(H)]
L=[[-1]*W for _ in range(H)]
R=[[-1]*W for _ in range(H)]

def u(i,j):
    if U[i][j]==-1 or U[i][j]==-2:
        if S[i][j]=='#':
            U[i][j]==-2
        elif i==0:
            U[i][j]=0
        elif U[i-1][j]==-1:
            u(i-1,j)
            if U[i-1][j]==-2:
                U[i][j]=0
            else:
                U[i][j]=U[i-1][j]+1
        elif U[i-1][j]==-2:
            U[i][j]=0
        else:
            U[i][j]=U[i-1][j]+1

def d(i,j):
    if D[i][j]==-1 or D[i][j]==-2:
        if S[i][j]=='#':
            D[i][j]==-2
        elif i==H-1:
            D[i][j]=0
        elif D[i+1][j]==-1:
            d(i+1,j)
            if D[i+1][j]==-2:
                D[i][j]=0
            else:
                D[i][j]=D[i+1][j]+1
        elif D[i+1][j]==-2:
            D[i][j]=0
        else:
            D[i][j]=D[i+1][j]+1

def l(i,j):
    if L[i][j]==-1 or L[i][j]==-2:
        if S[i][j]=='#':
            L[i][j]==-2
        elif j==0:
            L[i][j]=0
        elif L[i][j-1]==-1:
            l(i,j-1)
            if L[i][j-1]==-2:
                L[i][j]=0
            else:
                L[i][j]=L[i][j-1]+1
        elif L[i][j-1]==-2:
            L[i][j]=0
        else:
            L[i][j]=L[i][j-1]+1

def r(i,j):
    if R[i][j]==-1 or R[i][j]==-2:
        if S[i][j]=='#':
            R[i][j]==-2
        elif j==W-1:
            R[i][j]=0
        elif R[i][j+1]==-1:
            r(i,j+1)
            if R[i][j+1]==-2:
                R[i][j]=0
            else:
                R[i][j]=R[i][j+1]+1
        elif R[i][j+1]==-2:
            R[i][j]=0
        else:
            R[i][j]=R[i][j+1]+1

def udlr(i,j):
    if S[i][j]=='#':
        U[i][j]=D[i][j]=L[i][j]=R[i][j]=-2
        return 0
    else:
        if U[i][j]==-1:
            u(i,j)
        if D[i][j]==-1:
            d(i,j)
        if L[i][j]==-1:
            l(i,j)
        if R[i][j]==-1:
            r(i,j)
        return U[i][j]+D[i][j]+L[i][j]+R[i][j]+1

x=0
for i in range(H):
    for j in range(W):
        x=max(x,max(x,udlr(i,j)))
print(x)

Buggy submission (verdict: Runtime Error):
H,W=map(int, input().split())
S=[input() for _ in range(H)]
 
U=[[-1]*W for _ in range(H)]
D=[[-1]*W for _ in range(H)]
L=[[-1]*W for _ in range(H)]
R=[[-1]*W for _ in range(H)]
 
def u(i,j):
    if S[i][j]=='#':
        U[i][j]==-2
    elif i==0:
        U[i][j]=0
    elif U[i-1][j]==-1:
        u(i-1,j)
        if U[i-1][j]==-2:
            U[i][j]=0
        else:
            U[i][j]=U[i-1][j]+1
    elif U[i-1][j]==-2:
        U[i][j]=0
    else:
        U[i][j]=U[i-1][j]+1
 
def d(i,j):
    if S[i][j]=='#':
        D[i][j]==-2
    elif i==H-1:
        D[i][j]=0
    elif D[i+1][j]==-1:
        d(i+1,j)
        if D[i+1][j]==-2:
            D[i][j]=0
        else:
            D[i][j]=D[i+1][j]+1
    elif D[i+1][j]==-2:
        D[i][j]=0
    else:
        D[i][j]=D[i+1][j]+1
 
def l(i,j):
    if S[i][j]=='#':
        L[i][j]==-2
    elif j==0:
        L[i][j]=0
    elif L[i][j-1]==-1:
        l(i,j-1)
        if L[i][j-1]==-2:
            L[i][j]=0
        else:
            L[i][j]=L[i][j-1]+1
    elif L[i][j-1]==-2:
        L[i][j]=0
    else:
        L[i][j]=L[i][j-1]+1
 
def r(i,j):
    if S[i][j]=='#':
        R[i][j]==-2
    elif j==W-1:
        R[i][j]=0
    elif R[i][j+1]==-1:
        r(i,j+1)
        if R[i][j+1]==-2:
            R[i][j]=0
        else:
            R[i][j]=R[i][j+1]+1
    elif R[i][j+1]==-2:
        R[i][j]=0
    else:
        R[i][j]=R[i][j+1]+1
 
def udlr(i,j):
    if S[i][j]=='#':
        U[i][j]=D[i][j]=L[i][j]=R[i][j]=-2
        return 0
    else:
        if U[i][j]==-1:
            u(i,j)
        if D[i][j]==-1:
            d(i,j)
        if L[i][j]==-1:
            l(i,j)
        if R[i][j]==-1:
            r(i,j)
        return U[i][j]+D[i][j]+L[i][j]+R[i][j]+1
 
x=0
for i in range(H):
    for j in range(W):
        x=max(x,max(x,udlr(i,j)))
print(x)

Buggy submission (verdict: Runtime Error):
H,W=map(int, input().split())
S=[input() for _ in range(H)]
 
U=[[-1]*W for _ in range(H)]
D=[[-1]*W for _ in range(H)]
L=[[-1]*W for _ in range(H)]
R=[[-1]*W for _ in range(H)]
 
def u(i,j):
    if S[i][j]=='#':
        U[i][j]==-2
    elif i==0:
        U[i][j]=0
    elif U[i-1][j]==-1:
        u(i-1,j)
        if U[i-1][j]==-2:
            U[i][j]=0
        else:
            U[i][j]=U[i-1][j]+1
    elif U[i-1][j]==-2:
        U[i][j]=0
    else:
        U[i][j]=U[i-1][j]+1
 
def d(i,j):
    if S[i][j]=='#':
        D[i][j]==-2
    elif i==H-1:
        D[i][j]=0
    elif D[i+1][j]==-1:
        d(i+1,j)
        if D[i+1][j]==-2:
            D[i][j]=0
        else:
            D[i][j]=D[i+1][j]+1
    elif D[i+1][j]==-2:
        D[i][j]=0
    else:
        D[i][j]=D[i+1][j]+1
 
def l(i,j):
    if S[i][j]=='#':
        L[i][j]==-2
    elif j==0:
        L[i][j]=0
    elif L[i][j-1]==-1:
        l(i,j-1)
        if L[i][j-1]==-2:
            L[i][j]=0
        else:
            L[i][j]=L[i][j-1]+1
    elif L[i][j-1]==-2:
        L[i][j]=0
    else:
        L[i][j]=L[i][j-1]+1
 
def r(i,j):
    if S[i][j]=='#':
        R[i][j]==-2
    elif j==W-1:
        R[i][j]=0
    elif R[i][j+1]==-1:
        r(i,j+1)
        if R[i][j+1]==-2:
            R[i][j]=0
        else:
            R[i][j]=R[i][j+1]+1
    elif R[i][j+1]==-2:
        R[i][j]=0
    else:
        R[i][j]=R[i][j+1]+1
 
def udlr(i,j):
    if S[i][j]=='#':
        U[i][j]=D[i][j]=L[i][j]=R[i][j]=-2
        return 0
    else:
        if U[i][j]==-1:
            u(i,j)
        if D[i][j]==-1:
            d(i,j)
        if L[i][j]==-1:
            l(i,j)
        if R[i][j]==-1:
            r(i,j)
        return U[i][j]+D[i][j]+L[i][j]+R[i][j]+1
 
x=0
for i in range(H):
    for j in range(W):
        x=max(x,max(x,udlr(i,j)))
print(x)

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

U=[[-1]*W for _ in range(H)]
D=[[-1]*W for _ in range(H)]
L=[[-1]*W for _ in range(H)]
R=[[-1]*W for _ in range(H)]

def u(i,j):
    if S[i][j]=='#':
        U[i][j]==-2
    elif i==0:
        U[i][j]=0
    elif U[i-1][j]==-1:
        u(i-1,j)
        if U[i-1][j]==-2:
            U[i][j]=0
        else:
            U[i][j]=U[i-1][j]+1
    elif U[i-1][j]==-2:
        U[i][j]=0
    else:
        U[i][j]=U[i-1][j]+1

def d(i,j):
    if S[i][j]=='#':
        D[i][j]==-2
    elif i==H-1:
        D[i][j]=0
    elif D[i+1][j]==-1:
        d(i+1,j)
        if D[i+1][j]==-2:
            D[i][j]=0
        else:
            D[i][j]=D[i+1][j]+1
    elif D[i+1][j]==-2:
        D[i][j]=0
    else:
        D[i][j]=D[i+1][j]+1

def l(i,j):
    if S[i][j]=='#':
        L[i][j]==-2
    elif j==0:
        L[i][j]=0
    elif L[i][j-1]==-1:
        l(i,j-1)
        if L[i][j-1]==-2:
            L[i][j]=0
        else:
            L[i][j]=L[i][j-1]+1
    elif L[i][j-1]==-2:
        L[i][j]=0
    else:
        L[i][j]=L[i][j-1]+1

def r(i,j):
    if S[i][j]=='#':
        R[i][j]==-2
    elif j==W-1:
        R[i][j]=0
    elif R[i][j+1]==-1:
        r(i,j+1)
        if R[i][j+1]==-2:
            R[i][j]=0
        else:
            R[i][j]=R[i][j+1]+1
    elif R[i][j+1]==-2:
        R[i][j]=0
    else:
        R[i][j]=R[i][j+1]+1

def udlr(i,j):
    if S[i][j]=='#':
        U[i][j]=D[i][j]=L[i][j]=R[i][j]=-2
        return 0
    else:
        if U[i][j]==-1:
            u(i,j)
        if D[i][j]==-1:
            d(i,j)
        if L[i][j]==-1:
            l(i,j)
        if R[i][j]==-1:
            r(i,j)
        return U[i][j]+D[i][j]+L[i][j]+R[i][j]+1

x=0
for i in range(H):
    for j in range(W):
        x=max(x,max(x,udlr(i,j)))
print(x)