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

Solution (Python):
h, w = map(int, input().split())
s = [input() for _ in range(h)]

front_is_air = False
count = 0


left = [[0]*w for _ in range(h)]

for i in range(h):
    for j in range(w):
        if front_is_air:
            if s[i][j] == ".":
                count += 1
                left[i][j] = count
            else:
                front_is_air = False
                count = 0

        else:
            if s[i][j] == ".":
                front_is_air = True
                count += 1
                left[i][j] = count

        if j == w-1:
            front_is_air = False
            count = 0


right = [[0]*w for _ in range(h)]

for i in range(h):
    for j in range(w-1, -1, -1):
        if front_is_air:
            if s[i][j] == ".":
                count += 1
                right[i][j] = count
            else:
                front_is_air = False
                count = 0

        else:
            if s[i][j] == ".":
                front_is_air = True
                count += 1
                right[i][j] = count

        if j == 0:
            front_is_air = False
            count = 0


up = [[0]*w for _ in range(h)]

for i in range(w):
    for j in range(h):
        if front_is_air:
            if s[j][i] == ".":
                count += 1
                up[j][i] = count
            else:
                front_is_air = False
                count = 0

        else:
            if s[j][i] == ".":
                count += 1
                front_is_air = True
                up[j][i] = count

        if j == h-1:
            front_is_air = False
            count = 0


down = [[0]*w for _ in range(h)]

for i in range(w):
    for j in range(h-1, -1, -1):
        if front_is_air:
            if s[j][i] == ".":
                count += 1
                down[j][i] = count
            else:
                front_is_air = False
                count = 0

        else:
            if s[j][i] == ".":
                count += 1
                front_is_air = True
                down[j][i] = count

        if j == 0:
            front_is_air = False
            count = 0


memo = []

for i in range(h):
    for j in range(w):
        memo.append(left[i][j] + right[i][j] + up[i][j] + down[i][j] - 3)

print(max(memo))

Solution (Python):


def main():
    h,w = map(int,input().split())
    s=[]
    for i in range(h):
        s.append(list(input()) )
    
    l=[[0]*w for _ in range(h)]
    for i in range(h):
        count=0
        for j in range(w):
            if s[i][j] ==".":
                count+=1
            else:
                count=0
            l[i][j]=count
            
    r=[[0]*w for _ in range(h)]
    for i in range(h-1,-1,-1):
        count=0
        for j in range(w-1,-1,-1):
            if s[i][j] ==".":
                count+=1
            else:
                count=0
            r[i][j]=count
                    
    d=[[0]*w for _ in range(h)]
    for j in range(w-1,-1,-1):
        count=0
        for i in range(h-1,-1,-1):
            if s[i][j] ==".":
                count+=1
            else:
                count=0
            d[i][j]=count
                    
    u=[[0]*w for _ in range(h)]
    for j in range(w):
        count=0
        for i in range(h):
            if s[i][j] ==".":
                count+=1
            else:
                count=0
            u[i][j]=count
    
    ans=[[0]*w for _ in range(h)]
    for i in range(h):
        for j in range(w):
            ans[i][j] = l[i][j]+ r[i][j]+ u[i][j]+ d[i][j]-3
    print( max( max(ans[i]) for i in range(h)) )

if __name__ == '__main__':
    main()

Solution (Python):
import numpy as np 
H, W = map(int, input().split())
S = (np.array([list(input()) for _ in range(H)]) == '.')
 

up = np.zeros((H, W), dtype=int)
down = np.zeros((H, W), dtype=int)
left = np.zeros((H, W), dtype=int)
right = np.zeros((H, W), dtype=int)
 
for i in range(H):
    up[i] = (up[i-1] + 1) * S[i]
    down[-i-1] = (down[-i] + 1) * S[-i-1]
    
for i in range(W):
    left[:, i] = (left[:, i-1] + 1) * S[:, i]
    right[:, -i-1] = (right[:, -i] + 1) * S[:, -i-1]

print(np.max(up+down+left+right) - 3)

Solution (Python):
H, W = map(int, input().split())
S = [input() for _ in range(H)]
L, R, U, D = [[[0]*W for _ in range(H)] for i in range(4)]

for h in range(H):
    for w in range(W):
        if S[h][w] == '.':
            L[h][w] = L[h][w-1]+1
            U[h][w] = U[h-1][w]+1
        if S[h][W-1-w] == '.':
            R[h][-w-1] = R[h][-w]+1
        if S[H-1-h][w] == '.':
            D[-h-1][w] = D[-h][w]+1

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

print(ans)

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

grid2 = [[0]*W for i in range(H)]
grid3 = [[0]*W for i in range(H)]
for i in range(H):
    for j in range(W):
        if grid[i][j] == "
            grid2[i][j] = 0
        else:
            if j > 0:
                grid2[i][j] = grid2[i][j-1]+1
            else:
                grid2[i][j] = 1
    for j in reversed(range(W)):
        if grid2[i][j] != 0 and j != W-1:
            grid2[i][j] = max(grid2[i][j], grid2[i][j+1])

for j in range(W):
    for i in range(H):
        if grid[i][j] == "
            grid3[i][j] = 0
        else:
            if i > 0:
                grid3[i][j] = grid3[i-1][j]+1
            else:
                grid3[i][j] = 1
    for i in reversed(range(H)):
        if grid3[i][j] != 0 and i != H-1:
            grid3[i][j] = max(grid3[i][j], grid3[i+1][j])
ans = 0
for i in range(H):
    for j in range(W):
        ans = max(ans, grid2[i][j] + grid3[i][j] - 1)

print(ans)

Solution (Python):
import numpy as np 
H, W = map(int, input().split())
S = np.array([list(input()) for _ in range(H)]) == '.'
 

up = np.zeros((H, W), dtype=int)
down = np.zeros((H, W), dtype=int)
left = np.zeros((H, W), dtype=int)
right = np.zeros((H, W), dtype=int)
 
for i in range(H):
    up[i] = (up[i-1] + 1) * S[i]
    down[-i-1] = (down[-i] + 1) * S[-i-1]
    
for i in range(W):
    left[:, i] = (left[:, i-1] + 1) * S[:, i]
    right[:, -i-1] = (right[:, -i] + 1) * S[:, -i-1]

print(np.max(up+down+left+right) - 3)