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:
H, W = map(int, input().split())
S = []
for i in range(H):
    S.append(list(input()))

d = [[[None,None,None,None] for x in range(W)] for y in range(H)]

answer = 0
for i in range(H):
    for j in range(W):
        tmp = [0, 0, 0, 0]

        if S[i][j] == '#':
            continue
            
        # 上
        org_i = i
        
        while(org_i - 1>= 0):
            org_i -= 1
            if S[org_i ][j] == '#':
                break
            else:
                tmp[0] += 1
                c = d[org_i][j][0] 
                if c is not None:
                    tmp[0] += c
                    break
                
        d[i][j][0] = tmp[0]
        
        # 下
        org_i = i
        
        while(org_i + 1 < H):
            org_i += 1
            if S[org_i ][j] == '#':
                break
            else:
                tmp[1] += 1
                c = d[org_i][j][1] 
                if c is not None:
                    tmp[1] += c
                    break
                
        d[i][j][1] = tmp[1]
        
        # 右
        org_j = j
        
        while(org_j -1 >= 0):
            org_j -= 1
            if S[i ][org_j] == '#':
                break
            else:
                tmp[2] += 1
                c = d[i][org_j][2] 
                if c is not None:
                    tmp[2] += c
                    break
        
        d[i][j][2] = tmp[2]
        
        # 左
        org_j = j
        
        while(org_j + 1 < W):
            org_j += 1
            if S[i][org_j] == '#':
                break
            else:
                tmp[3] += 1
                c = d[i][org_j][3] 
                if c is not None:
                    tmp[3] += c
                    break
            
        d[i][j][3] = tmp[3]
        
        m = sum(d[i][j]) + 1
        if m > answer:
            answer = m
                
print(answer)

Submission status: Time Limit Exceeded

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

d = [[[None,None,None,None] for x in range(W)] for y in range(H)]

answer = 0
for i in range(H):
    for j in range(W):
        tmp = [0, 0, 0, 0]

        if S[i][j] == '#':
            continue
            
        # 上
        org_i = i
        
        while(org_i - 1>= 0):
            org_i -= 1
            if S[org_i ][j] == '#':
                break
            else:
                tmp[0] += 1
                c = d[org_i][j][0] 
                if c:
                    tmp[0] += c
                    break
                
        d[i][j][0] = tmp[0]
        
        # 下
        org_i = i
        
        while(org_i + 1 < H):
            org_i += 1
            if S[org_i ][j] == '#':
                break
            else:
                tmp[1] += 1
                c = d[org_i][j][1] 
                if c:
                    tmp[1] += c
                    break
                
        d[i][j][1] = tmp[1]
        
        # 右
        org_j = j
        
        while(org_j -1 >= 0):
            org_j -= 1
            if S[i ][org_j] == '#':
                break
            else:
                tmp[2] += 1
                c = d[i][org_j][2] 
                if c:
                    tmp[2] += c
                    break
        
        d[i][j][2] = tmp[2]
        
        # 左
        org_j = j
        
        while(org_j + 1 < W):
            org_j += 1
            if S[i][org_j] == '#':
                break
            else:
                tmp[3] += 1
                c = d[i][org_j][3] 
                if c:
                    tmp[3] += c
                    break
            
        d[i][j][3] = tmp[3]
        
        m = sum(d[i][j]) + 1
        if m > answer:
            answer = m
                
print(answer)

Submission status: Time Limit Exceeded

Solution code:
H, W = map(int, input().split())
S = []
for i in range(H):
    S.append(list(input()))
    
d = [[[0,0,0,0] for x in range(W)] for y in range(H)]
answer = 0
for i in range(H):
    for j in range(W):
        tmp = [0, 0, 0, 0]

        if S[i][j] == '#':
            continue
            
        # 上
        org_i = i
        
        while(org_i - 1>= 0):
            org_i -= 1
            if S[org_i ][j] == '#':
                break
            else:
                tmp[0] += 1
                c = d[org_i][j][0] 
                if c > 0:
                    tmp[0] += c
                    break
                
        d[i][j][0] = tmp[0]
        
        # 下
        org_i = i
        
        while(org_i + 1 < H):
            org_i += 1
            if S[org_i ][j] == '#':
                break
            else:
                tmp[1] += 1
                c = d[org_i][j][1] 
                if c > 0:
                    tmp[1] += c
                    break
                
        d[i][j][1] = tmp[1]
        
        # 右
        org_j = j
        
        while(org_j -1 >= 0):
            org_j -= 1
            if S[i ][org_j] == '#':
                break
            else:
                tmp[2] += 1
                c = d[i][org_j][2] 
                if c > 0:
                    tmp[2] += c
                    break
        
        d[i][j][2] = tmp[2]
        
        # 左
        org_j = j
        
        while(org_j + 1 < W):
            org_j += 1
            if S[i][org_j] == '#':
                break
            else:
                tmp[3] += 1
                c = d[i][org_j][3] 
                if c > 0:
                    tmp[3] += c
                    break
            
        d[i][j][3] = tmp[3]
        
        m = sum(d[i][j]) + 1
        if m > answer:
            answer = m
                
print(answer)

Submission status: Time Limit Exceeded

Solution code:
H, W = map(int, input().split())
S = []
for i in range(H):
    S.append(list(input()))
    
d = [[[0,0,0,0] for x in range(W)] for y in range(H)]
answer = 0
for i in range(H):
    for j in range(W):
        tmp = [0, 0, 0, 0]

        if S[i][j] == '#':
            continue
            
        # 上
        org_i = i
        
        while(org_i - 1>= 0):
            org_i -= 1
            if S[org_i ][j] == '#':
                break
            elif  S[org_i ][j] == '.':
                tmp[0] += 1
                c = d[org_i][j][0] 
                if c > 0:
                    tmp[0] += c
                    break
                
        d[i][j][0] = tmp[0]
        
        # 下
        org_i = i
        
        while(org_i + 1 < H):
            org_i += 1
            if S[org_i ][j] == '#':
                break
            elif  S[org_i ][j] == '.':
                tmp[1] += 1
                c = d[org_i][j][1] 
                if c > 0:
                    tmp[1] += c
                    break
                
        d[i][j][1] = tmp[1]
        
        # 右
        org_j = j
        
        while(org_j -1 >= 0):
            org_j -= 1
            if S[i ][org_j] == '#':
                break
            elif  S[i ][org_j] == '.':
                tmp[2] += 1
                c = d[i][org_j][2] 
                if c > 0:
                    tmp[2] += c
                    break
        
        d[i][j][2] = tmp[2]
        
        # 左
        org_j = j
        
        while(org_j + 1 < W):
            org_j += 1
            if S[i][org_j] == '#':
                break
            elif S[i][org_j] == '.':
                tmp[3] += 1
                c = d[i][org_j][3] 
                if c > 0:
                    tmp[3] += c
                    break
            
        d[i][j][3] = tmp[3]
        
        m = sum(d[i][j]) + 1
        if m > answer:
            answer = m
                
print(answer)

Submission status: Time Limit Exceeded

Solution code:
H, W = map(int, input().split())
S = []
for i in range(H):
    S.append(list(input()))
    
answer = 0
for i in range(H):
    for j in range(W):
        m = 1
        if S[i][j] == '#':
            continue
            
        # 上
        org_i = i
        
        while(org_i - 1>= 0):
            org_i -= 1
            if S[org_i ][j] == '#':
                break
            m += 1
        
        # 下
        org_i = i
        
        while(org_i + 1 < H):
            org_i += 1
            if S[org_i ][j] == '#':
                break
            m += 1
        
        # 右
        org_j = j
        
        while(org_j -1 >= 0):
            org_j -= 1
            if S[i ][org_j] == '#':
                break
            m += 1
        
        # 左
        org_j = j
        
        while(org_j + 1 < W):
            org_j += 1
            if S[i][org_j] == '#':
                break
            m += 1
        
        if m > answer:
            answer = m
        
print(answer)

Submission status: Time Limit Exceeded

Solution code:
import sys
def input():
    return sys.stdin.readline()[:-1]
sys.setrecursionlimit(1000000)

h,w=map(int,input().split())
maze = [[]for _ in range(h)]
for i in range(h):
    maze[i].extend(list(input()))

R=[[0 for i in range(w)]for i in range(h)]
L=[[0 for i in range(w)]for i in range(h)]
U=[[0 for i in range(w)]for i in range(h)]
B=[[0 for i in range(w)]for i in range(h)]

for i in range(h):
    for j in range(w):
        if maze[i][j]=="#":continue
        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):
    for j in range(w):
        if maze[h-1-i][w-1-j]=="#":continue
        if i==0:B[h-1-i][w-1-j]=1
        else: B[h-1-i][w-1-j] = B[h-i][w-1-j]+1
        if j==0:R[h-1-i][w-1-j]=1
        else: R[h-1-i][w-1-j] = R[h-1-i][w-j]+1


#print(*B,sep="\n")
#print("\n")
#print(*U,sep="\n")


ma=0
for i in range(h):
    for j in range(w):
        if maze[i][j]=="#":continue
        ma=max(ma,R[i][j]+L[i][j]+U[i][j]+B[i][j]-3)

print(ma)

Submission status: Time Limit Exceeded

Solution code:
H,W = map(int, input().split())

S_array = [["#" for _ in range(W+2)]] + [["#"] + list(input()) + ["#"] for i in range(H)] + [["#" for _ in range(W+2)]]

def connection_check(target_list):
    connection = 0
    connection_list = list()
    
    for i in range(len(target_list)):
        if target_list[i]=="#":
            connection_list += [connection for _ in range(connection)]
            connection_list += [0]
            connection = 0
        elif target_list[i]==".":
            connection += 1
    
    return connection_list

W_connection_array = [[0 for _ in range(W+2)]] + [connection_check(S_array[i]) for i in range(1,H+1)] + [[0 for _ in range(W+2)]]
H_connection_array = [[0 for _ in range(H+2)]] + [connection_check([row[i] for row in S_array]) for i in range(1,W+1)] + [[0 for _ in range(H+2)]]

#print(W_connection_array)
#print(H_connection_array)

ans = 0

for i in range(1,H+1):
    for j in range(1,W+1):
        temp_ans = W_connection_array[i][j] + H_connection_array[j][i]
        if ans < temp_ans:
            ans = temp_ans

print(ans - 1) #自分自身の分の重複加算を引く

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

H, W = map(int,input().split())
S = [list(str(input())) for _ in range(H)]
S = np.array(S)
S = (S == '.') * 1

R = np.array([[0 for _ in range(W)] for __ in  range(H)])
L = np.array([[0 for _ in range(W)] for __ in  range(H)])
U = np.array([[0 for _ in range(W)] for __ in  range(H)])
D = np.array([[0 for _ in range(W)] for __ in  range(H)])

for i in range(W):
    if i == 0:
        L[:, 0] = S[:, 0]
        R[:, W - 1] = S[:, W - 1]
    else:
        L[:, i] = L[:, i - 1] * S[:, i] + S[:, i]
        R[:, W - i - 1] = R[:, W - i] * S[:, W - i - 1] + S[:, W - i - 1]
for i in range(H):
    if i == 0:
        U[i] = S[i]
        D[H - 1] = S[H - 1]
    else:
        U[i] = U[i - 1] * S[i] + S[i]
        D[H - i - 1] = D[H - i] * S[H - i - 1] + S[H - i - 1]

print(np.max(R + L + U + D) - 3)

Submission status: Time Limit Exceeded

Solution code:
def main():
    H, W = map(int, input().split())
    S = [list(input()) for _ in range(H)]
    
    left = [[-1]*W for _ in range(H)]
    right = [[-1]*W for _ in range(H)]
    up = [[-1]*W for _ in range(H)]
    down = [[-1]*W for _ in range(H)]

    for i in range(H):
        for j in range(W):
            if S[i][j] == '.':
                if j == 0:
                    left[i][j] = 0
                else:
                    left[i][j] = left[i][j-1] + 1
                if i == 0:
                    up[i][j] = 0
                else:
                    up[i][j] = up[i-1][j] + 1

            if S[-1-i][-1-j] == '.':
                if j == 0:
                    right[-1-i][-1-j] = 0
                else:
                    right[-1-i][-1-j] = right[-1-i][-1-(j-1)] + 1
                if i == 0:
                    down[-1-i][-1-j] = 0
                else:
                    down[-1-i][-1-j] = down[-1-(i-1)][-1-j] + 1

    ans = 0
    temp = [0] * W
    for i in range(H):
        for j in range(W):
            temp[j] = left[i][j] + right[i][j] + down[i][j] + up[i][j] + 1
        ans = max(ans, max(temp))
    print(ans)

main()

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

def main():
    H, W = map(int, input().split())
    S = [list(input()) for _ in range(H)]
    
    left = np.zeros([H, W], dtype=np.int) - 1
    right = np.zeros([H, W], dtype=np.int) - 1
    up = np.zeros([H, W], dtype=np.int) - 1
    down = np.zeros([H, W], dtype=np.int) - 1

    for i in range(H):
        for j in range(W):
            if S[i][j] == '.':
                if j == 0:
                    left[i][j] = 0
                else:
                    left[i][j] = left[i][j-1] + 1
                if i == 0:
                    up[i][j] = 0
                else:
                    up[i][j] = up[i-1][j] + 1
            
            if S[-1-i][-1-j] == '.':
                if j == 0:
                    right[-1-i][-1-j] = 0
                else:
                    right[-1-i][-1-j] = right[-1-i][-1-(j-1)] + 1
                if i == 0:
                    down[-1-i][-1-j] = 0
                else:
                    down[-1-i][-1-j] = down[-1-(i-1)][-1-j] + 1
                
    print(np.max(left+right+up+down) + 1)

main()

Submission status: Time Limit Exceeded

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

    left = [[-1]*W for _ in range(H)]
    right = [[-1]*W for _ in range(H)]
    up = [[-1]*W for _ in range(H)]
    down = [[-1]*W for _ in range(H)]

    for i in range(H):
        for j in range(W):
            if S[i][j] == '.':
                if j == 0:
                    left[i][j] = 0
                else:
                    left[i][j] = left[i][j-1] + 1

    for i in range(H):
        for j in range(W):
            if S[-1-i][-1-j] == '.':        
                if j == 0:
                    right[-1-i][-1-j] = 0
                else:
                    right[-1-i][-1-j] = right[-1-i][-1-(j-1)] + 1

    for i in range(H):
        for j in range(W):
            if S[i][j] == '.':
                if i == 0:
                    up[i][j] = 0
                else:
                    up[i][j] = up[i-1][j] + 1

    for i in range(H):
        for j in range(W):
            if S[-1-i][-1-j] == '.':
                if i == 0:
                    down[-1-i][-1-j] = 0
                else:
                    down[-1-i][-1-j] = down[-1-(i-1)][-1-j] + 1
            
    ans = 0
    temp = [0] * W
    for i in range(H):
        for j in range(W):
            temp[j] = left[i][j] + right[i][j] + down[i][j] + up[i][j] + 1
        ans = max(ans, max(temp))
    print(ans)

main()

Submission status: Time Limit Exceeded

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

    left = [[None]*W for _ in range(H)]
    right = [[None]*W for _ in range(H)]
    up = [[None]*W for _ in range(H)]
    down = [[None]*W for _ in range(H)]

    for i in range(H):
        for j in range(W):
            if S[i][j] == '.':
                if j == 0:
                    left[i][j] = 0
                else:
                    left[i][j] = left[i][j-1] + 1
            else:
                left[i][j] = -1

    for i in range(H):
        for j in range(W):
            if S[-1-i][-1-j] == '.':        
                if j == 0:
                    right[-1-i][-1-j] = 0
                else:
                    right[-1-i][-1-j] = right[-1-i][-1-(j-1)] + 1
            else:
                right[-1-i][-1-j] = -1

    for i in range(H):
        for j in range(W):
            if S[i][j] == '.':
                if i == 0:
                    up[i][j] = 0
                else:
                    up[i][j] = up[i-1][j] + 1
            else:
                up[i][j] = -1

    for i in range(H):
        for j in range(W):
            if S[-1-i][-1-j] == '.':
                if i == 0:
                    down[-1-i][-1-j] = 0
                else:
                    down[-1-i][-1-j] = down[-1-(i-1)][-1-j] + 1
            else:
                down[-1-i][-1-j] = -1
            
    ans = 0
    temp = [0] * W
    for i in range(H):
        for j in range(W):
            temp[j] = left[i][j] + right[i][j] + down[i][j] + up[i][j] + 1
        ans = max(ans, max(temp))
    print(ans)

main()

Submission status: Time Limit Exceeded

Solution code:
def main():
    H, W = map(int, input().split())
    S = [list(input()) for _ in range(H)]
    
    left = [[None]*W for _ in range(H)]
    right = [[None]*W for _ in range(H)]
    up = [[None]*W for _ in range(H)]
    down = [[None]*W for _ in range(H)]

    for i in range(H):
        for j in range(W):
            if S[i][j] == '.':
                if j == 0:
                    left[i][j] = 0
                else:
                    left[i][j] = left[i][j-1] + 1
                if i == 0:
                    up[i][j] = 0
                else:
                    up[i][j] = up[i-1][j] + 1
            else:
                left[i][j] = -1
                up[i][j] = -1
            
            if S[-1-i][-1-j] == '.':
                if j == 0:
                    right[-1-i][-1-j] = 0
                else:
                    right[-1-i][-1-j] = right[-1-i][-1-(j-1)] + 1
                if i == 0:
                    down[-1-i][-1-j] = 0
                else:
                    down[-1-i][-1-j] = down[-1-(i-1)][-1-j] + 1
            else:
                right[-1-i][-1-j] = -1
                down[-1-i][-1-j] = -1

    ans = 0
    temp = [0] * W
    for i in range(H):
        for j in range(W):
            temp[j] = left[i][j] + right[i][j] + down[i][j] + up[i][j] + 1
        ans = max(ans, max(temp))
    print(ans)

main()

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

def main():
    H, W = map(int, input().split())
    S = [list(input()) for _ in range(H)]
    
    left = np.zeros([H, W], dtype=np.int)
    right = np.zeros([H, W], dtype=np.int)
    up = np.zeros([H, W], dtype=np.int)
    down = np.zeros([H, W], dtype=np.int)

    for i in range(H):
        for j in range(W):
            if S[i][j] == '.':
                if j == 0:
                    left[i][j] = 0
                else:
                    left[i][j] = left[i][j-1] + 1
                if i == 0:
                    up[i][j] = 0
                else:
                    up[i][j] = up[i-1][j] + 1
            else:
                left[i][j] = -1
                up[i][j] = -1
            
            if S[-1-i][-1-j] == '.':
                if j == 0:
                    right[-1-i][-1-j] = 0
                else:
                    right[-1-i][-1-j] = right[-1-i][-1-(j-1)] + 1
                if i == 0:
                    down[-1-i][-1-j] = 0
                else:
                    down[-1-i][-1-j] = down[-1-(i-1)][-1-j] + 1
            else:
                right[-1-i][-1-j] = -1
                down[-1-i][-1-j] = -1
                
    print(np.max(left+right+up+down) + 1)

main()

Submission status: Time Limit Exceeded

Solution code:
h, w = map(int, input().split())
s = [str(input()) for i in range(h)]
m = 1
for i in range(h):
    for j in range(w):
        if s[i][j] == '.':
            u, d, r, l, cnt = 1, 1, 1, 1, 1
            while 0 <= i - u:
                if s[i - u][j] == '#':
                    break
                cnt += 1
                u += 1
            while i + d < h:
                if s[i + d][j] == '#':
                    break
                cnt += 1
                d += 1
            while 0 <= j - l:
                if s[i][j - l] == '#':
                    break
                cnt += 1
                l += 1
            while j + r < w:
                if s[i][j + r] == '#':
                    break
                cnt += 1
                r += 1
            m = max(m, cnt)
print(m)

Submission status: Time Limit Exceeded

Solution code:
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
from itertools import accumulate
from itertools import permutations
from itertools import combinations
from collections import defaultdict
from collections import Counter
import fractions
import math
from collections import deque
from bisect import bisect_left
from bisect import insort_left
import itertools
from heapq import heapify
from heapq import heappop
from heapq import heappush
import heapq
import numpy as np
INF = float("inf")
#d = defaultdict(int)
#d = defaultdict(list)
#N = int(input())
#A = list(map(int,input().split()))
#S = list(input())
#S.remove("\n")
#N,M = map(int,input().split())
#S,T = map(str,input().split())
#A = [int(input()) for _ in range(N)]
#S = [input() for _ in range(N)]
#A = [list(map(int,input().split())) for _ in range(N)]
H,W = map(int,input().split())
Map = [list(input())[:-1] for _ in range(H)]
hnum = [[0]*(W) for _ in range(H)]
wnum = [[0]*(W) for _ in range(H)]
for i in range(H):
    li = Map[i]
    q = deque([-1])
    for j in range(W):
        if li[j] == ".":
            if j == W-1:
                prev = q.popleft()
                for kk in range(prev+1,j+1):
                    hnum[i][kk] = W-prev-1
            else:
                continue
        else:
            prev = q.popleft()
            if j - prev >= 2:
                for k in range(prev+1,j):
                    hnum[i][k] = j - prev - 1
            q.append(j)
for i in range(W):
    q = deque([-1])
    for j in range(H):
        if Map[j][i] == ".":
            if j == H-1:
                prev = q.popleft()
                for kk in range(prev+1,j+1):
                    wnum[kk][i] = H-prev-1
            else:
                continue
        else:
            prev = q.popleft()
            if j - prev >= 2:
                for k in range(prev+1,j):
                    wnum[k][i] = j - prev - 1
            q.append(j)
MAX = 0
for i in range(H):
    for j in range(W):
        MAX = max(MAX,hnum[i][j]+wnum[i][j])
print(MAX-1)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

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

L = np.zeros((h, w), dtype=int)
R = np.zeros((h, w), dtype=int)
U = np.zeros((h, w), dtype=int)
D = np.zeros((h, w), dtype=int)

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

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

print(max(np.max(L + R + U + D - 3), 0))

Submission status: Time Limit Exceeded

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

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):
    if s[i][0] == '.':
        L[i][0] = 1
    if s[i][w-1] == '.':
        R[i][w-1] = 1
    for j in range(1, w):
        if s[i][j] == '.':
            L[i][j] = L[i][j-1] + 1
        if s[i][w-j-1] == '.':
            R[i][w-j-1] = R[i][w-j] + 1

for i in range(w):
    if s[0][i] == '.':
        U[0][i] = 1
    if s[h-1][i] == '.':
        D[h-1][i] = 1
    for j in range(1, h):
        if s[j][i] == '.':
            U[j][i] = U[j-1][i] + 1
        if s[h-j-1][i] == '.':
            D[h-j-1][i] = D[h-j][i] + 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:
h, w = map(int, input().split())
s = []
for i in range(h):
    s.append([1 if j == '.' else 0 for j in list(input())])

for i in range(h):
    cnt = -1
    start = -1
    for j in range(w):
        if s[i][j] > 0:
            cnt += 1
            if start == -1:
                start = j
        elif start != -1 and s[i][j] == 0:
            for k in range(start, j):
                s[i][k] += cnt
            cnt = -1
            start = -1
        if start != -1 and j == w-1:
            for k in range(start, w):
                s[i][k] += cnt
            cnt = -1
            start = -1

ans = 0
for j in range(w):
    cnt = -1
    start = -1
    for i in range(h):
        # print(cnt, start)
        if s[i][j] > 0:
            cnt += 1
            if start == -1:
                start = i
        elif start != -1 and s[i][j] == 0:
            for k in range(start, i):
                s[k][j] += cnt
                ans = max(ans, s[k][j])
            cnt = -1
            start = -1
        if start != -1 and i == h-1:
            for k in range(start, h):
                s[k][j] += cnt
                ans = max(ans, s[k][j])
            cnt = -1
            start = -1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
H, W = map(int,input().split())
S = []
for i in range(H):
    s = str(input())
    S.append(np.array([s[i] for i in range(W)]))
S = np.array(S)
LR = np.array([np.array([-1 for i in range(W)]) for j in range(H)])
UD = np.array([np.array([-1 for i in range(W)]) for j in range(H)])
count = 0
for h in range(H):
    for w in range(W):
        if S[h][w] == '#':
            LR[h][w] = 0
            LR[h][w-count:w] = np.array([count for i in range(count)])
            count = 0
        else:
            count += 1
    if count != 0:
        LR[h][-count:] = np.array([count for i in range(count)])
        count = 0
UD = UD.T
S = S.T
for w in range(W):
    for h in range(H):
        if S[w][h] == '#':
            UD[w][h] = 0
            UD[w][h-count:h] = np.array([count for i in range(count)])
            count = 0
        else:
            count += 1
    if count != 0:
        UD[w][-count:] = np.array([count for i in range(count)])
        count = 0
UD = UD.T
S = S.T
al = UD + LR
print(np.max(al)-1)

Submission status: Time Limit Exceeded

Solution code:

import sys
sys.setrecursionlimit(10**6)

#n=int(input())
#n,m=list(map(int,input().split()))
#a=list(map(int,input().split()))
input_list = lambda : list(map(int,input().split()))

h,w=input_list()
a=[[s for s in  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)]
u=[[0 for _ in range(w)] for _ in range(h)]
d=[[0 for _ in range(w)] for _ in range(h)]
#left
for w_i in range(1,w):
    for h_i in range(h):

        if a[h_i][w_i]=="#" or a[h_i][w_i-1]=="#":
            continue
        l[h_i][w_i]=l[h_i][w_i-1]+1
    
#right
for w_i in range(w-2,-1,-1):
    for h_i in range(h):

        if a[h_i][w_i]=="#" or a[h_i][w_i+1]=="#":
            continue
        r[h_i][w_i]=r[h_i][w_i+1]+1


#up
for w_i in range(w):
    for h_i in range(1,h):

        if a[h_i][w_i]=="#" or a[h_i-1][w_i]=="#":
            continue
        u[h_i][w_i]=u[h_i-1][w_i]+1


#down
for w_i in range(w):
    for h_i in range(h-2,-1,-1):

        if a[h_i][w_i]=="#" or a[h_i+1][w_i]=="#":
            continue
        d[h_i][w_i]=d[h_i+1][w_i]+1
ans=0
for w_i in range(w):
    for h_i in range(h):
        if a[h_i][w_i]=="#":
            continue
        cal=l[h_i][w_i]+r[h_i][w_i]+u[h_i][w_i]+d[h_i][w_i]+1
        ans=max(ans,cal)

print(ans)