Problem:


Score : 400 points

Problem Statement

There is a grid with H horizontal rows and W vertical columns, and there are obstacles on some of the squares.

Snuke is going to choose one of the squares not occupied by an obstacle and place a lamp on it.
The lamp placed on the square will emit straight beams of light in four cardinal directions: up, down, left, and right.
In each direction, the beam will continue traveling until it hits a square occupied by an obstacle or it hits the border of the grid. It will light all the squares on the way, including the square on which the lamp is placed, but not the square occupied by an obstacle.

Snuke wants to maximize the number of squares lighted by the lamp.

You are given H strings S_i (1 \leq i \leq H), each of length W. If the j-th character (1 \leq j \leq W) of S_i is #, there is an obstacle on the square at the i-th row from the top and the j-th column from the left; if that character is ., there is no obstacle on that square.

Find the maximum possible number of squares lighted by the lamp.

Constraints

1 \leq H \leq 2,000

1 \leq W \leq 2,000

S_i is a string of length W consisting of # and ..

. occurs at least once in one of the strings S_i (1 \leq i \leq H).

Input

Input is given from Standard Input in the following format:

H W
S_1
:
S_H

Output

Print the maximum possible number of squares lighted by the lamp.

Sample Input 1

4 6
#..#..
.....#
....#.
#.#...

Sample Output 1

8

If Snuke places the lamp on the square at the second row from the top and the second column from the left, it will light the following squares: the first through fifth squares from the left in the second row, and the first through fourth squares from the top in the second column, for a total of eight squares.

Sample Input 2

8 8
..#...#.
....#...
##......
..###..#
...#..#.
##....#.
#...#...
###.#..#

Sample Output 2

13



Sample input:
4 6
#..#..
.....#
....#.
#.#...


Sample output:
8

Submission status: Time Limit Exceeded

Solution code:
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 = [[-1 for i in range(w)] for j in range(h)]
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)]





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]
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)

Submission status: Time Limit Exceeded

Solution code:
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))

Submission status: Time Limit Exceeded

Solution code:
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(h):
    for j in range(w-1,-1,-1):
        if s[i][j] == "#":
            dp2[i][j] = 0
        elif j == w-1:
            dp2[i][j] = 1
        else:
            dp2[i][j] = 1 + dp2[i][j+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]
        a = max(a,dp1[i][j]+dp2[i][j]+dp3[i][j]+dp4[i][j]-3)

print(int(a))

Submission status: Time Limit Exceeded

Solution code:
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(h):
    for j in range(w-1,-1,-1):
        if s[i][j] == "#":
            dp2[i][j] = 0
        elif j == w-1:
            dp2[i][j] = 1
        else:
            dp2[i][j] = 1 + dp2[i][j+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]

for i in range(w):
    for j in range(h-1,-1,-1):
        if s[j][i] == "#":
            dp4[j][i] = 0
        elif j == h-1:
            dp4[j][i] = 1
        else:
            dp4[j][i] = 1 + dp4[j+1][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]
        a = max(a,dp1[i][j]+dp2[i][j]+dp3[i][j]+dp4[i][j]-3)

print(int(a))

Submission status: Time Limit Exceeded

Solution code:
# ABC129D - Lamp
import sys
input = sys.stdin.readline

def main():
    H, W = tuple(map(int, input().split()))
    S = tuple(input().rstrip() for _ in range(H))
    L, R = [[0] * W for _ in range(H)], [[0] * W for _ in range(H)]
    U, D = [[0] * W for _ in range(H)], [[0] * W for _ in range(H)]
    for i in range(H):
        for j in range(W):
            if S[i][j] == "#":
                L[i][j] == 0
                U[i][j] == 0
            else:
                if j == 0:
                    L[i][j] = 1
                else:
                    L[i][j] = L[i][j - 1] + 1
                if i == 0:
                    U[i][j] = 1
                else:
                    U[i][j] = U[i - 1][j] + 1
    for i in range(H - 1, -1, -1):
        for j in range(W - 1, -1, -1):
            if S[i][j] == "#":
                R[i][j] == 0
                D[i][j] == 0
            else:
                if j == W - 1:
                    R[i][j] = 1
                else:
                    R[i][j] = R[i][j + 1] + 1

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


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
# ABC129D - Lamp
import sys
input = sys.stdin.readline

def main():
    H, W = tuple(map(int, input().split()))
    S = tuple(input().rstrip() for _ in range(H))
    # T = tuple(zip(*S))  # slice S vertically
    L, R = [[0] * W for _ in range(H)], [[0] * W for _ in range(H)]
    U, D = [[0] * W for _ in range(H)], [[0] * W for _ in range(H)]
    for i in range(H):
        for j in range(W):
            if S[i][j] == "#":
                L[i][j] == 0
            else:
                if j == 0:
                    L[i][j] = 1
                else:
                    L[i][j] = L[i][j - 1] + 1
    for i in range(H):
        for j in range(W - 1, -1, -1):
            if S[i][j] == "#":
                R[i][j] == 0
            else:
                if j == W - 1:
                    R[i][j] = 1
                else:
                    R[i][j] = R[i][j + 1] + 1
    for i in range(H):
        for j in range(W):
            if S[i][j] == "#":
                U[i][j] == 0
            else:
                if i == 0:
                    U[i][j] = 1
                else:
                    U[i][j] = U[i - 1][j] + 1
    for i in range(H - 1, -1, -1):
        for j in range(W):
            if S[i][j] == "#":
                D[i][j] == 0
            else:
                if i == H - 1:
                    D[i][j] = 1
                else:
                    D[i][j] = D[i + 1][j] + 1

    ans = max(
        L[i][j] + R[i][j] + U[i][j] + D[i][j] - 3 for i in range(H) for j in range(W)
    )
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
def slove():
    import sys
    input = sys.stdin.readline
    h, w = list(map(int, input().rstrip('\n').split()))
    s = [str(input().rstrip('\n')) for _ in range(h)]
    L = [[0] * w for _ in range(h)]
    R = [[0] * w for _ in range(h)]
    U = [[0] * w for _ in range(h)]
    D = [[0] * w for _ in range(h)]
    for i in range(h):
        for j in range(w):
            if s[i][j] == "#":
                L[i][j] = 0
            else:
                if i == 0:
                    L[i][j] = 1
                else:
                    L[i][j] = L[i - 1][j] + 1
            if s[-i-1][j] == "#":
                R[-i-1][j] = 0
            else:
                if i == 0:
                    R[-i-1][j] = 1
                else:
                    R[-i-1][j] = R[-i][j] + 1
            if s[i][j] == "#":
                U[i][j] = 0
            else:
                if j == 0:
                    U[i][j] = 1
                else:
                    U[i][j] = U[i][j-1] + 1
            if s[i][-j-1] == "#":
                D[i][-j-1] = 0
            else:
                if j == 0:
                    D[i][-j-1] = 1
                else:
                    D[i][-j-1] = D[i][-j] + 1
    mn = 0
    for i in range(h):
        for j in range(w):
            mn = max(mn, U[i][j] + D[i][j] + L[i][j] + R[i][j] - 3)
    print(mn)


if __name__ == '__main__':
    slove()

Submission status: Time Limit Exceeded

Solution code:
def MAP(): return map(int,input().split())

H,W = MAP()
lst = [list(input()) for _ in range(H)]
L = [[0 for _ in range(W)] for _ in range(H)]
R = [[0 for _ in range(W)] for _ in range(H)]
D = [[0 for _ in range(W)] for _ in range(H)]
U = [[0 for _ in range(W)] for _ in range(H)]
for i in range(H):
    for j in range(W):
        #Left
        if lst[i][j]==".":
            L[i][j] = L[i][j-1]+1
        #Up
            U[i][j] = U[i-1][j]+1
        #Right
        if lst[i][-(j+1)]==".":
            R[i][-(j+1)] = R[i][-j]+1
        #Down
        if lst[-(i+1)][j]==".":
            D[-(i+1)][j] = D[-i][j]+1
ans=0
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)

Submission status: Time Limit Exceeded

Solution code:
def MAP(): return map(int,input().split())

H,W = MAP()
lst = [list(input()) for _ in range(H)]
ans=0
for i in range(H):
    for j in range(W):
        tmp=0
        if lst[i][j]=="#":
            continue
        #yoko
        for k in lst[i][j:]:
            if k=="#":
                break
            tmp+=1
        for k in range(j-1,-1,-1):
            if lst[i][k]=="#":
                break
            tmp+=1
        #tate
        for k in range(i,H):
            if lst[k][j]=="#":
                break
            tmp+=1
        for k in range(i-1,-1,-1):
            if lst[k][j]=="#":
                break
            tmp+=1
        ans = max(ans,tmp-1)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
H, W = map(int,input().split())
S = []
for h in range(H):
   S.append(input())
def calc(LR,RL,H,W,S):
   for h in range(H):
       for w in range(W):
           if S[h][w]==".":
               LR[h+1][w+1] = LR[h+1][w] + 1
           else:
               LR[h+1][w+1] = 0
           if S[h][W-w-1]==".":
               RL[h+1][W-w] = RL[h+1][W-w+1] + 1
           else:
               RL[h+1][W-w] = 0
   return LR, RL
LR = np.zeros((H+2,W+2)).astype(np.int)
RL = np.zeros((H+2,W+2)).astype(np.int)
UD = np.zeros((H+2,W+2)).astype(np.int)
DU = np.zeros((H+2,W+2)).astype(np.int)
LR, RL = calc(LR,RL,H,W,S)
S2 = ["" for i in range(len(S[0]))]
for i in range(len(S[0])):
   for j in range(len(S)):
       S2[i]+=(S[j][i])

UD, DU = calc(UD.T,DU.T,W,H,S2)
mx = 0
for h in range(H):
   for w in range(W):
       p = 0
       if (S[h][w]=="."):
           p = LR[h+1][w]+RL[h+1][w+2] + UD.T[h][w+1]+DU.T[h+2][w+1] + 1
           mx = max(mx,p)
print (mx)

Submission status: Time Limit Exceeded

Solution code:
def slove():
    import sys
    input = sys.stdin.readline
    h, w = list(map(int, input().rstrip('\n').split()))
    s = [list(str(input().rstrip('\n'))) for _ in range(h)]
    a = [[[0] * 4 for _ in range(w)] for _ in range(h)]
    for i in range(h):
        for j in range(w):
            if s[i][j] == "#":
                a[i][j][0] = 0
            else:
                if i == 0:
                    a[i][j][0] = 1
                else:
                    a[i][j][0] = a[i - 1][j][0] + 1
            if s[-i-1][j] == "#":
                a[-i-1][j][1] = 0
            else:
                if i == 0:
                    a[-i-1][j][1] = 1
                else:
                    a[-i-1][j][1] = a[-i][j][1] + 1
            if s[i][j] == "#":
                a[i][j][2] = 0
            else:
                if j == 0:
                    a[i][j][2] = 1
                else:
                    a[i][j][2] = a[i][j-1][2] + 1
            if s[i][-j-1] == "#":
                a[i][-j-1][3] = 0
            else:
                if j == 0:
                    a[i][-j-1][3] = 1
                else:
                    a[i][-j-1][3] = a[i][-j][3] + 1
    mn = 0
    for i in range(h):
        for j in range(w):
            mn = max(mn, sum(a[i][j]) - 3)
    print(mn)


if __name__ == '__main__':
    slove()

Submission status: Time Limit Exceeded

Solution code:
def slove():
    import sys
    input = sys.stdin.readline
    h, w = list(map(int, input().rstrip('\n').split()))
    s = [str(input().rstrip('\n')) for _ in range(h)]
    a = [[[0] * 4 for _ in range(w)] for _ in range(h)]
    for i in range(h):
        for j in range(w):
            if s[i][j] == "#":
                a[i][j][0] = 0
            else:
                if i == 0:
                    a[i][j][0] = 1
                else:
                    a[i][j][0] = a[i - 1][j][0] + 1

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

            if s[i][j] == "#":
                a[i][j][2] = 0
            else:
                if j == 0:
                    a[i][j][2] = 1
                else:
                    a[i][j][2] = a[i][j-1][2] + 1

            if s[i][-j-1] == "#":
                a[i][-j-1][3] = 0
            else:
                if j == 0:
                    a[i][-j-1][3] = 1
                else:
                    a[i][-j-1][3] = a[i][-j][3] + 1
    mn = 0
    for i in range(h):
        for j in range(w):
            mn = max(mn, sum(a[i][j]) - 3)
    print(mn)


if __name__ == '__main__':
    slove()

Submission status: Time Limit Exceeded

Solution code:
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 = [[-1 for i in range(w)] for j in range(h)]
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)]



for i in range(h):
    for j in range(w-1,-1,-1):
        if s[i][j] == "#":
            dp2[i][j] = 0
        elif j == w-1:
            dp2[i][j] = 1
        else:
            dp2[i][j] = 1 + dp2[i][j+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]

for i in range(w):
    for j in range(h-1,-1,-1):
        if s[j][i] == "#":
            dp4[j][i] = 0
        elif j == h-1:
            dp4[j][i] = 1
        else:
            dp4[j][i] = 1 + dp4[j+1][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]
        a = max(a,dp1[i][j]+dp2[i][j]+dp3[i][j]+dp4[i][j]-3)

print(a)

Submission status: Time Limit Exceeded

Solution code:
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 = [[-1 for i in range(w)] for j in range(h)]
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)]

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]

for i in range(h):
    for j in range(w-1,-1,-1):
        if s[i][j] == "#":
            dp2[i][j] = 0
        elif j == w-1:
            dp2[i][j] = 1
        else:
            dp2[i][j] = 1 + dp2[i][j+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]

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

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)

Submission status: Time Limit Exceeded

Solution code:
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 = [[-1 for i in range(w)] for j in range(h)]
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)]
dp=[dp1,dp2,dp3,dp4]

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]

for i in range(h):
    for j in range(w-1,-1,-1):
        if s[i][j] == "#":
            dp2[i][j] = 0
        elif j == w-1:
            dp2[i][j] = 1
        else:
            dp2[i][j] = 1 + dp2[i][j+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]

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

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)

Submission status: Time Limit Exceeded

Solution code:
h, w = map(int, input().split())
lst = []
for i in range(h):
    lst.append(list(input()))

R = [[0]*w for _ in range(h)]
L = [[0]*w for _ in range(h)]
U = [[0]*w for _ in range(h)]
D = [[0]*w for _ in range(h)]

for i in range(h):
    for j in range(w):
        if lst[i][j] == '.':
            if j == 0:
                L[i][j] = 1
            else:
                L[i][j] = L[i][j-1] + 1
        

for i in range(h):
    for j in range(w-1, -1, -1):
        if lst[i][j] == '.':
            if j == w-1:
                R[i][j] = 1
            else:
                R[i][j] = R[i][j+1] + 1            


for i in range(h):
    for j in range(w):
        if lst[i][j] == '.':
            if i == 0:
                U[i][j] = 1
            else:
                U[i][j] = U[i-1][j] + 1

for i in range(h-1, -1, -1):
    for j in range(w):
        if lst[i][j] == '.':
            if i == h-1:
                D[i][j] = 1
            else:
                D[i][j] = D[i+1][j] + 1

ans = 0
x = [[0]*w for _ in range(h)]
for i in range (h):
    for j in range(w):
        x[i][j] = L[i][j] + R[i][j] + U[i][j] + D[i][j] - 3
    ans = max(ans, max(x[i]))
print(ans)

Submission status: Time Limit Exceeded

Solution code:
h, w = map(int, input().split())
lst = []
for i in range(h):
    lst.append(list(input()))

R = [[0]*w for _ in range(h)]
L = [[0]*w for _ in range(h)]
U = [[0]*w for _ in range(h)]
D = [[0]*w for _ in range(h)]

for i in range(h):
    for j in range(w):
        if lst[i][j] == '.':
            if j == 0:
                L[i][j] = 1
            else:
                L[i][j] = L[i][j-1] + 1
        

for i in range(h):
    for j in range(w-1, -1, -1):
        if lst[i][j] == '.':
            if j == w-1:
                R[i][j] = 1
            else:
                R[i][j] = R[i][j+1] + 1            


for i in range(h):
    for j in range(w):
        if lst[i][j] == '.':
            if i == 0:
                U[i][j] = 1
            else:
                U[i][j] = U[i-1][j] + 1

for i in range(h-1, -1, -1):
    for j in range(w):
        if lst[i][j] == '.':
            if i == h-1:
                D[i][j] = 1
            else:
                D[i][j] = D[i+1][j] + 1

ans = 0
x = [[0]*w for _ in range(h)]
for i in range (h):
    for j in range(w):
        x[i][j] = L[i][j] + R[i][j] + U[i][j] + D[i][j] - 3
        ans = max(ans, max(x[i]))
print(ans)

Submission status: Time Limit Exceeded

Solution code:
h, w = map(int, input().split())
lst = []
for i in range(h):
    lst.append(list(input()))

R = [[0]*w for _ in range(h)]
L = [[0]*w for _ in range(h)]
U = [[0]*w for _ in range(h)]
D = [[0]*w for _ in range(h)]

for i in range(h):
    for j in range(w):
        if lst[i][j] == '.':
            if j == 0:
                L[i][j] = 1
            else:
                L[i][j] = L[i][j-1] + 1
        

for i in range(h):
    for j in range(w-1, -1, -1):
        if lst[i][j] == '.':
            if j == w-1:
                R[i][j] = 1
            else:
                R[i][j] = R[i][j+1] + 1            


for i in range(h):
    for j in range(w):
        if lst[i][j] == '.':
            if i == 0:
                U[i][j] = 1
            else:
                U[i][j] = U[i-1][j] + 1

for i in range(h-1, -1, -1):
    for j in range(w):
        if lst[i][j] == '.':
            if i == h-1:
                D[i][j] = 1
            else:
                D[i][j] = D[i+1][j] + 1

ans = 0
x = [[0]*w for _ in range(h)]
for i in range (h):
    for j in range(w):
        x[i][j] = L[i][j] + R[i][j] + U[i][j] + D[i][j] - 3
        ans = max(ans, x[i][j])
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import copy
h,w = map(int,input().split())
s = [list(input()) for _ in range(h)]
l,r,u,d,S = [[0]*w for _ in range(h)],[[0]*w for _ in range(h)],[[0]*w for _ in range(h)],[[0]*w for _ in range(h)],[[0]*w for _ in range(h)]
for i in range(h):
  if s[i][0] == ".":
    l[i][0] = 1
  for j in range(1,w):
    if s[i][j] == ".":
      l[i][j] = l[i][j-1] + 1
#print(l)
for i in range(h):
  if s[i][w-1] == ".":
    r[i][w-1] = 1
  for j in range(w-2,-1,-1):
    if s[i][j] == ".":
      r[i][j] = r[i][j+1] + 1
#print(r)
for i in range(w):
  if s[0][i] == ".":
    u[0][i] = 1
  for j in range(1,h):
    if s[j][i] == ".":
      u[j][i] = u[j-1][i] + 1
#print(u)
for i in range(w):
  if s[h-1][i] == ".":
    d[h-1][i] = 1
  for j in range(h-2,-1,-1):
    if s[j][i] == ".":
      d[j][i] = d[j+1][i] + 1
m = 0
for i in range(h):
  for j in range(w):
    m = max(m,l[i][j]+r[i][j]+u[i][j]+d[i][j]-3)
print(m)

Submission status: Time Limit Exceeded

Solution code:
import copy
import numpy as np
h,w = map(int,input().split())
s = [list(input()) for _ in range(h)]
l,r,u,d,S = [[0]*w for _ in range(h)],[[0]*w for _ in range(h)],[[0]*w for _ in range(h)],[[0]*w for _ in range(h)],[[0]*w for _ in range(h)]
for i in range(h):
  if s[i][0] == ".":
    l[i][0] = 1
  for j in range(1,w):
    if s[i][j] == ".":
      l[i][j] = l[i][j-1] + 1
#print(l)
for i in range(h):
  if s[i][w-1] == ".":
    r[i][w-1] = 1
  for j in range(w-2,-1,-1):
    if s[i][j] == ".":
      r[i][j] = r[i][j+1] + 1
#print(r)
for i in range(w):
  if s[0][i] == ".":
    u[0][i] = 1
  for j in range(1,h):
    if s[j][i] == ".":
      u[j][i] = u[j-1][i] + 1
#print(u)
for i in range(w):
  if s[h-1][i] == ".":
    d[h-1][i] = 1
  for j in range(h-2,-1,-1):
    if s[j][i] == ".":
      d[j][i] = d[j+1][i] + 1

for i in range(h):
  for j in range(w):
    S[i][j] = max(0,l[i][j]+r[i][j]+u[i][j]+d[i][j]-3)

print(np.amax(S))

Submission status: Time Limit Exceeded

Solution code:
h, w = map(int, input().split())

m = []
for i in range(h):
    row = [0 if a == "#" else 1 for a in list(input())]
    m.append(row)

res = 0
for i in range(h):
    for j in range(w):
        a = m[i][j]
        if a == 0:
            continue
        cnt = 1

        k = i -1
        while k >= 0:
            if m[k][j] == 0:
                break
            k -= 1
            cnt += 1

        k = i + 1
        while k < h:
            if m[k][j] == 0:
                break
            k += 1
            cnt += 1

        l = j - 1
        while l >= 0:
            if m[i][l] == 0:
                break
            l -= 1
            cnt += 1

        l = j + 1
        while l < w:
            if m[i][l] == 0:
                break
            l += 1
            cnt += 1

        res = max(res, cnt)

print(res)

Submission status: Time Limit Exceeded

Solution code:
a = input().split()
height = int(a[0])
width = int(a[1])

area = []
for i in range(height):
    area.append([i == "#" for i in list(input())])

import numpy as np

L = np.zeros((height, width))
R = np.zeros((height, width))
U = np.zeros((height, width))
D = np.zeros((height, width))

for h_idx in range(L.shape[0]):
    for w_idx in range(L.shape[1]):
        if w_idx == 0:
            L[h_idx][w_idx] = 0
        elif area[h_idx][w_idx - 1] == False:
            L[h_idx][w_idx] = L[h_idx][w_idx-1] + 1
        else:
            L[h_idx][w_idx] = 0

for h_idx in range(R.shape[0]):
    for w_idx in reversed(range(R.shape[1])):
        if w_idx == (R.shape[1]-1):
            R[h_idx][w_idx] = 0
        elif area[h_idx][w_idx + 1] == False:
            R[h_idx][w_idx] = R[h_idx][w_idx + 1] + 1
        else:
            L[h_idx][w_idx] = 0

for w_idx in range(U.shape[1]):
    for h_idx in range(U.shape[0]):
        if h_idx == 0:
            U[h_idx][w_idx] = 0
        elif area[h_idx -1][w_idx] == False:
            U[h_idx][w_idx] = U[h_idx-1][w_idx] + 1
        else:
            U[h_idx][w_idx] = 0

for w_idx in range(D.shape[1]):
    for h_idx in reversed(range(D.shape[0])):
        if h_idx == (D.shape[0] - 1):
            D[h_idx][w_idx] = 0
        elif area[h_idx + 1][w_idx] == False:
            D[h_idx][w_idx] = D[h_idx+1][w_idx] + 1
        else:
            D[h_idx][w_idx] = 0

max = 0

for h_idx in range(height):
    for w_idx in range(width):
        value = L[h_idx][w_idx] + R[h_idx][w_idx] + U[h_idx][w_idx] + D[h_idx][w_idx] + 1
        if value > max and area[h_idx][w_idx] == False:
            max = value
            i = h_idx
            j = w_idx
print(int(max))

Submission status: Time Limit Exceeded

Solution code:
import collections
def main():
    H, W = map(int, input().split())
    grid = []
    for _ in range(H):
        grid.append(input())

    rows = []
    rows_val = dict()
    id = 0
    for i in range(H):
        count = 0
        temp = []
        id += 1
        for j in range(W):
            if grid[i][j] == "#":
                if count > 0:
                    rows_val[id] = count
                count = 0
                id += 1
                temp.append(None)
            else:
                temp.append(id)
                count += 1
        if count > 0:
            rows_val[id] = count
        rows.append(temp)
    # print(rows)

    cols = []
    cols_val = dict()
    id = 0
    for j in range(W):
        count = 0
        temp = []
        id += 1
        for i in range(H):
            if grid[i][j] == "#":
                if count > 0:
                    cols_val[id] = count
                count = 0
                id += 1
                temp.append(None)
            else:
                count += 1
                temp.append(id)
        if count > 0:
            cols_val[id] = count
        cols.append(temp)

    max_v = 0
    for i in range(H):
        for j in range(W):
            if grid[i][j] == ".":
                v = rows_val[rows[i][j]]
                v += cols_val[cols[j][i]] - 1 # -1 for overlap
                max_v = max(max_v, v)
    return max_v


if __name__ == '__main__':
    print(main())

Submission status: Time Limit Exceeded

Solution code:
def main():
    H, W = map(int, input().split())
    grid = []
    for _ in range(H):
        grid.append(input())

    rows = []
    for i in range(H):
        count = 0
        temp = []
        for j in range(W):
            if grid[i][j] == "#":
                temp += [count]*count
                temp += [0]
                count = 0
            else:
                count += 1
        temp += [count]*count
        rows.append(temp)
    cols = []
    for j in range(W):
        count = 0
        temp = []
        for i in range(H):
            if grid[i][j] == "#":
                temp += [count]*count
                temp += [0]
                count = 0
            else:
                count += 1
        temp += [count]*count
        cols.append(temp)

    max_v = 0
    for i in range(H):
        for j in range(W):
            if grid[i][j] == ".":
                v = rows[i][j] + cols[j][i] - 1 # -1 for overlap
                max_v = max(max_v, v )
    return max_v


if __name__ == '__main__':
    print(main())