Problem p03014 (python)

Fixed submission:
h,w = map(int,input().split(" "))
s = [[0 for i in range(w)] for j in range(h)]
for i in range(h):
    tmp = list(input())
    for j in range(w):
        s[i][j] = tmp[j]

dp1= []
dp2= [[-1 for i in range(w)] for j in range(h)]
dp3=[]
dp4=[[-1 for i in range(w)] for j in range(h)]


for i in range(h):
    dp1.append([])
    dp3.append([])
    for j in range(w):
        dp1[i].append(-1)
        dp3[i].append(-1)

        if s[i][j] == "#":
            dp1[i][j] = 0
        elif j == 0:
            dp1[i][j] = 1
        else:
            dp1[i][j] = 1 + dp1[i][j-1]

        if s[i][w-j-1] == "#":
            dp2[i][w-j-1] = 0
        elif w-j-1 == w-1:
            dp2[i][w-j-1] = 1
        else:
            dp2[i][w-j-1] = 1 + dp2[i][w-j]

        if s[i][j] == "#":
            dp3[i][j] = 0
        elif i == 0:
            dp3[i][j] = 1
        else:
            dp3[i][j] = 1 + dp3[i-1][j]

        if s[h-i-1][j] == "#":
            dp4[h-i-1][j] = 0
        elif h-i-1 == h-1:
            dp4[h-i-1][j] = 1
        else:
            dp4[h-i-1][j] = 1 + dp4[h-i][j]



        

a = 1
for i in range(h):
    for j in range(w):
        a = max(a,dp1[i][j]+dp2[i][j]+dp3[i][j]+dp4[i][j]-3)


print(a)

Buggy submission (verdict: Runtime Error):
import numpy as np

h,w = map(int,input().split(" "))
s = [[0 for i in range(w)] for j in range(h)]
for i in range(h):
    tmp = list(input())
    for j in range(w):
        s[i][j] = tmp[j]

dp1 = np.full((2000,2000),-1)
dp2 = np.full((2000,2000),-1)
dp3 = np.full((2000,2000),-1)
dp4 = np.full((2000,2000),-1)





for i in range(w):
    for j in range(h):
        if s[j][i] == "#":
            dp3[j][i] = 0
        elif j == 0:
            dp3[j][i] = 1
        else:
            dp3[j][i] = 1 + dp3[j-1][i]

        if s[h-j-1][i] == "#":
            dp4[h-j-1][i] = 0
        elif h-j-1 == h-1:
            dp4[h-j-1][i] = 1
        else:
            dp4[h-j-1][i] = 1 + dp4[h-j][i]


a = 1
for i in range(h):
    for j in range(w):
        if s[i][j] == "#":
            dp1[i][j] = 0
        elif j == 0:
            dp1[i][j] = 1
        else:
            dp1[i][j] = 1 + dp1[i][j-1]

        if s[i][w-j-1] == "#":
            dp2[i][w-j-1] = 0
        elif w-j-1 == w-1:
            dp2[i][w-j-1] = 1
        else:
            dp2[i][w-j-1] = 1 + dp2[i][w-j]

dp1 = dp1+dp2+dp3+dp4

max = max(1,np.max(dp1)-3)

print(int(max))

Buggy submission (verdict: Runtime Error):
h,w = map(int,input().split(" "))
s = [[0 for i in range(w)] for j in range(h)]
for i in range(h):
    tmp = list(input())
    for j in range(w):
        s[i][j] = tmp[j]
dp2 = [[-1 for i in range(w)] for j in range(h)]
dp3 = [[-1 for i in range(w)] for j in range(h)]
dp4 = [[-1 for i in range(w)] for j in range(h)]
dp5 = [[-1 for i in range(w)] for j in range(h)]
dp=[dp2,dp3,dp4,dp5]

def search2(array,x,y,i,j,dp):
            if i>=0 and i<=x-1 and j>=0 and j<=y-1 and array[i][j] != "#":
                if dp[0][i][j] == -1:
                    dp[0][i][j] = 1+search2(array,x,y,i-1,j,dp)
                    return dp[0][i][j]
                else:
                    return dp[0][i][j]
            elif i>=0 and i<=x-1 and j>=0 and j<=y-1:
                dp[0][i][j] = 0
            return 0

def search3(array,x,y,i,j,dp):
            if i>=0 and i<=x-1 and j>=0 and j<=y-1 and array[i][j] != "#":
                 if dp[1][i][j] == -1:
                    dp[1][i][j] = 1+search3(array,x,y,i+1,j,dp)
                    return dp[1][i][j]
                 else:
                    return dp[1][i][j]
            elif i>=0 and i<=x-1 and j>=0 and j<=y-1:
                dp[1][i][j] = 0
            return 0

def search4(array,x,y,i,j,dp):
            if i>=0 and i<=x-1 and j>=0 and j<=y-1 and array[i][j] != "#":
                if dp[2][i][j] == -1:
                    dp[2][i][j] = 1+search4(array,x,y,i,j-1,dp)
                    return dp[2][i][j]
                else:
                    return dp[2][i][j]
            elif i>=0 and i<=x-1 and j>=0 and j<=y-1:
                dp[2][i][j] = 0
            return 0

def search5(array,x,y,i,j,dp):
            if i>=0 and i<=x-1 and j>=0 and j<=y-1 and array[i][j] != "#":
                if dp[3][i][j] == -1:
                    dp[3][i][j] = 1+search5(array,x,y,i,j+1,dp)
                    return dp[3][i][j]
                else:
                    return  dp[3][i][j]
            elif i>=0 and i<=x-1 and j>=0 and j<=y-1:
                dp[3][i][j] = 0
            return 0

            
max = 1
for i in range(h):
    a = 0
    for j in range(w):
        a = search2(s,h,w,i,j,dp) + search3(s,h,w,i,j,dp)+ search4(s,h,w,i,j,dp) + search5(s,h,w,i,j,dp)
        if a-3 > max:
            max = a-3

print(max)

Buggy submission (verdict: Runtime Error):
h,w = map(int,input().split(" "))
s = [[0 for i in range(w)] for j in range(h)]
for i in range(h):
    tmp = list(input())
    for j in range(w):
        s[i][j] = tmp[j]
dp2 = [[-1 for i in range(w)] for j in range(h)]
dp3 = [[-1 for i in range(w)] for j in range(h)]
dp4 = [[-1 for i in range(w)] for j in range(h)]
dp5 = [[-1 for i in range(w)] for j in range(h)]
dp=[dp2,dp3,dp4,dp5]
def search(array,x,y,i,j,dp):
            if i>=0 and i<=x-1 and j>=0 and j<=y-1 and array[i][j] != "#":
                return -3+search2(array,x,y,i,j,dp)+search3(array,x,y,i,j,dp)+search4(array,x,y,i,j,dp)+search5(array,x,y,i,j,dp)
def search2(array,x,y,i,j,dp):
            if i>=0 and i<=x-1 and j>=0 and j<=y-1 and array[i][j] != "#":
                if dp[0][i][j] == -1:
                    dp[0][i][j] = 1+search2(array,x,y,i-1,j,dp)
                    return dp[0][i][j]
                else:
                    return dp[0][i][j]
            elif i>=0 and i<=x-1 and j>=0 and j<=y-1:
                dp[0][i][j] = 0
            return 0

def search3(array,x,y,i,j,dp):
            if i>=0 and i<=x-1 and j>=0 and j<=y-1 and array[i][j] != "#":
                 if dp[1][i][j] == -1:
                    dp[1][i][j] = 1+search3(array,x,y,i+1,j,dp)
                    return dp[1][i][j]
                 else:
                    return dp[1][i][j]
            elif i>=0 and i<=x-1 and j>=0 and j<=y-1:
                dp[1][i][j] = 0
            return 0

def search4(array,x,y,i,j,dp):
            if i>=0 and i<=x-1 and j>=0 and j<=y-1 and array[i][j] != "#":
                if dp[2][i][j] == -1:
                    dp[2][i][j] = 1+search4(array,x,y,i,j-1,dp)
                    return dp[2][i][j]
                else:
                    return dp[2][i][j]
            elif i>=0 and i<=x-1 and j>=0 and j<=y-1:
                dp[2][i][j] = 0
            return 0

def search5(array,x,y,i,j,dp):
            if i>=0 and i<=x-1 and j>=0 and j<=y-1 and array[i][j] != "#":
                if dp[3][i][j] == -1:
                    dp[3][i][j] = 1+search5(array,x,y,i,j+1,dp)
                    return dp[3][i][j]
                else:
                    return  dp[3][i][j]
            elif i>=0 and i<=x-1 and j>=0 and j<=y-1:
                dp[3][i][j] = 0
            return 0

            
max = 1
for i in range(h):
    for j in range(w):
        search2(s,h,w,i,j,dp)
        search3(s,h,w,i,j,dp)
        search4(s,h,w,i,j,dp)
        search5(s,h,w,i,j,dp)
for i in range(h):
    for j in range(w):
        a = 0
        for k in range(len(dp)):
            a += dp[k][i][j]
            if a-3 > max:
                max = a-3

print(max)

Buggy submission (verdict: Runtime Error):
h,w = map(int,input().split(" "))
s = [[0 for i in range(w)] for j in range(h)]
for i in range(h):
    tmp = list(input())
    for j in range(w):
        s[i][j] = tmp[j]
dp2 = [[-1 for i in range(w)] for j in range(h)]
dp3 = [[-1 for i in range(w)] for j in range(h)]
dp4 = [[-1 for i in range(w)] for j in range(h)]
dp5 = [[-1 for i in range(w)] for j in range(h)]
dp=[dp2,dp3,dp4,dp5]
def search(array,x,y,i,j,dp):
            if i>=0 and i<=x-1 and j>=0 and j<=y-1 and array[i][j] != "#":
                return -3+search2(array,x,y,i,j,dp)+search3(array,x,y,i,j,dp)+search4(array,x,y,i,j,dp)+search5(array,x,y,i,j,dp)
            else:
                return 0
def search2(array,x,y,i,j,dp):
            if i>=0 and i<=x-1 and j>=0 and j<=y-1 and array[i][j] != "#":
                if dp[0][i][j] == -1:
                    dp[0][i][j] = 1+search2(array,x,y,i-1,j,dp)
                    return dp[0][i][j]
                else:
                    return dp[0][i][j]
            elif i>=0 and i<=x-1 and j>=0 and j<=y-1:
                dp[0][i][j] = 0
            return 0

def search3(array,x,y,i,j,dp):
            if i>=0 and i<=x-1 and j>=0 and j<=y-1 and array[i][j] != "#":
                 if dp[1][i][j] == -1:
                    dp[1][i][j] = 1+search3(array,x,y,i+1,j,dp)
                    return dp[1][i][j]
                 else:
                    return dp[1][i][j]
            elif i>=0 and i<=x-1 and j>=0 and j<=y-1:
                dp[1][i][j] = 0
            return 0

def search4(array,x,y,i,j,dp):
            if i>=0 and i<=x-1 and j>=0 and j<=y-1 and array[i][j] != "#":
                if dp[2][i][j] == -1:
                    dp[2][i][j] = 1+search4(array,x,y,i,j-1,dp)
                    return dp[2][i][j]
                else:
                    return dp[2][i][j]
            elif i>=0 and i<=x-1 and j>=0 and j<=y-1:
                dp[2][i][j] = 0
            return 0

def search5(array,x,y,i,j,dp):
            if i>=0 and i<=x-1 and j>=0 and j<=y-1 and array[i][j] != "#":
                if dp[3][i][j] == -1:
                    dp[3][i][j] = 1+search5(array,x,y,i,j+1,dp)
                    return dp[3][i][j]
                else:
                    return  dp[3][i][j]
            elif i>=0 and i<=x-1 and j>=0 and j<=y-1:
                dp[3][i][j] = 0
            return 0

            
max = 1
for i in range(h):
    for j in range(w):
        a = search(s,h,w,i,j,dp)
        if max<a: 
            max= a

print(max)

Buggy submission (verdict: Runtime Error):
h,w = map(int,input().split(" "))
s = [[0 for i in range(w)] for j in range(h)]
for i in range(h):
    tmp = list(input())
    for j in range(w):
        s[i][j] = tmp[j]
def search(array,x,y,i,j):
            if i>=0 and i<=x-1 and j>=0 and j<=y-1 and array[i][j] != "#":
                return 1+search2(array,x,y,i-1,j)+search3(array,x,y,i+1,j)+search4(array,x,y,i,j+1)+search5(array,x,y,i,j-1)
            else:
                return 0
def search2(array,x,y,i,j):
            if i>=0 and i<=x-1 and j>=0 and j<=y-1 and array[i][j] != "#":
                return 1+search2(array,x,y,i-1,j)
            else:
                return 0

def search3(array,x,y,i,j):
            if i>=0 and i<=x-1 and j>=0 and j<=y-1 and array[i][j] != "#":
                return 1+search3(array,x,y,i+1,j)
            else:
                return 0

def search4(array,x,y,i,j):
            if i>=0 and i<=x-1 and j>=0 and j<=y-1 and array[i][j] != "#":
                return 1+search4(array,x,y,i,j+1)
            else:
                return 0

def search5(array,x,y,i,j):
            if i>=0 and i<=x-1 and j>=0 and j<=y-1 and array[i][j] != "#":
                return 1+search5(array,x,y,i,j-1)
            else:
                return 0

            



max = 1
for i in range(h):
    for j in range(w):
        a = search(s,h,w,i,j)
        if max<a: 
            max= a
print(max)