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

ss = [[] for i in range(h)]

for i in range(h):
  ss[i] = list(str(input()))

s_h_l = [[0]*w for i in range(h)]
for i in range(h):
  light = 0
  for j in range(w):
    s_h_l[i][j] = light
    if ss[i][j] == '.':
      light += 1
    else:
      light = 0
      s_h_l[i][j] = 0
      
s_h_r = [[0]*w for i in range(h)]
for i in range(h):
  light = 0
  for j in reversed(range(w)):
    s_h_r[i][j] = light
    if ss[i][j] == '.':
      light += 1
    else:
      light = 0
      s_h_r[i][j] = 0

s_w_u = [[0]*w for i in range(h)]
for i in range(w):
  light = 0
  for j in range(h):
    s_w_u[j][i] = light
    if ss[j][i] == '.':
      light += 1
    else:
      light = 0
      s_w_u[j][i] = 0
      
s_w_d = [[0]*w for i in range(h)]
for i in range(w):
  light = 0
  for j in reversed(range(h)):
    s_w_d[j][i] = light
    if ss[j][i] == '.':
      light += 1
    else:
      light = 0
      s_w_d[j][i] = 0   

ans = 0
for i in range(h):
  for j in range(w):
    ans = max(ans, s_h_r[i][j]+s_h_l[i][j]+s_w_u[i][j]+s_w_d[i][j]+1)
print(ans)

Solution (Python):


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

u = [[0 for i in range(w)] for j in range(h)]
d = [[0 for i in range(w)] for j in range(h)]
l = [[0 for i in range(w)] for j in range(h)]
r = [[0 for i in range(w)] for j in range(h)]

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

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

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

Solution (Python):

import sys


def solve(H: int, W: int, S: "List[str]"):
    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):
            if S[i][j] != '
                if j == 0:
                    L[i][j] = 1
                else:
                    L[i][j] = L[i][j-1] + 1
            jj = W - 1 - j
            if S[i][jj] != '
                if jj == W-1:
                    R[i][jj] = 1
                else:
                    R[i][jj] = R[i][jj+1] + 1
            if S[i][j] != '
                if i == 0:
                    D[i][j] = 1
                else:
                    D[i][j] = D[i-1][j] + 1
            ii = H - 1 - i
            if S[ii][j] != '
                if ii == H-1:
                    U[ii][j] = 1
                else:
                    U[ii][j] = U[ii+1][j] + 1
    mx = 0 
    for i in range(H):
        for j in range(W):
            m = L[i][j] + R[i][j] + U[i][j] + D[i][j] - 3
            if mx < m:
                mx = m
    print(int(mx))


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    H = int(next(tokens))  
    W = int(next(tokens))  
    S = [ next(tokens) for _ in range(H) ]  
    solve(H, W, S)

if __name__ == '__main__':
    main()

Solution (Python):

import numpy as np

def solve():
    H, W = list(map(int, input().split()))
    grid = []
    for _ in range(H):
        grid.append(list(input()))
    grid = (np.array(grid) == ".")*1  

    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(W):
        if i == 0:
            L[:, i] = grid[:, i]
        else:
            L[:, i] = (L[:, i-1] + 1) * grid[:, i]

    for i in range(W-1, -1, -1):
        if i == W-1:
            R[:, i] = grid[:, i]
        else:
            R[:, i] = (R[:, i+1] + 1) * grid[:, i]

    for i in range(H):
        if i == 0:
            U[i, :] = grid[i, :]
        else:
            U[i, :] = (U[i-1, :] + 1) * grid[i, :]
    
    for i in range(H-1, -1, -1):
        if i == H-1:
            D[i, :] = grid[i, :]
        else:
            D[i, :] = (D[i+1, :] + 1) * grid[i, :]
    
    ans = np.max(L+R+U+D-3)
    print(ans)

if __name__ == "__main__":
    solve()

Solution (Python):
def D_Lamp():
    import numpy as np
    
    h, w = map(int, input().split())
    S = np.array([list(input()) for _ in range(h)]) == "."
    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 row in range(h):
        D[row] =(D[row - 1] + 1) * S[row]
        U[-row - 1] = (U[-row] + 1) * S[-row -1]
    
    for col in range(w):
        R[:, col] = (R[:, col - 1] + 1) * S[:, col]
        L[:, -col - 1] = (L[:, -col] + 1) * S[:, -col-1]
    num_max = 0
    print(np.max(L+R+U+D) - 3)

if __name__ == "__main__":
    D_Lamp()

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





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

for y in range(h):
    c = 0
    left = 0
    for x in range(w + 1):
        if x < w and field[y][x] == ".":
            c += 1
        else:
            for pos in range(left, x):
                cntx[y][pos] = c
            c = 0
            left = x + 1
for x in range(w):
    c = 0
    left = 0
    for y in range(h + 1):
        if y < h and field[y][x] == ".":
            c += 1
        else:
            for pos in range(left, y):
                cnty[pos][x] = c
            c = 0
            left = y + 1






maxv = 0
for y in range(h):
    for x in range(w):
        maxv = max(maxv, cntx[y][x] + cnty[y][x] - 1)
print(maxv)

Solution (Python):
H, W = map(int, input().split())
meiro = [list(input()) for i in range(H)]
right = [[0 for _ in range(W)] for _ in range(H)]
left= [[0 for _ in range(W)] for _ in range(H)]
up = [[0 for _ in range(W)] for _ in range(H)]
down = [[0 for _ in range(W)] for _ in range(H)]
for i in range(H):
    cur=0
    for j in range(W):
        if meiro[i][j]=="
            cur = 0
        else:
            cur +=1
        left[i][j]=cur
for i in range(H):
    cur=0
    for j in range(W-1,-1,-1):
        if meiro[i][j]=="
            cur = 0
        else:
            cur +=1
        right[i][j]=cur
for i in range(W):
    cur=0
    for j in range(H):
        if meiro[j][i]=="
            cur = 0
        else:
            cur +=1
        up[j][i]=cur
for i in range(W):
    cur=0
    for j in range(H-1,-1,-1):
        if meiro[j][i]=="
            cur = 0
        else:
            cur +=1
        down[j][i]=cur
res = 0
for i in range(H):
    for j in range(W):
        res = max(res,right[i][j]+left[i][j]+up[i][j]+down[i][j]-3)
print(res)

Solution (Python):
import numpy as np

h,w=map(int,input().split())
s=[]
for i in range(h):
    s.append(list(input()))
grid=(np.array(s) ==".") *1

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 j in range(w):
    if j == 0:
        l[:,j] = grid[:,j]
    else:
        l[:,j] = (l[:,j-1]+1) * grid[:,j]
for j in range(w-1,-1,-1):
    if j == (w-1):
        r[:,j] = grid[:,j]
    else:
        r[:,j] = (r[:,j+1] +1)*grid[:,j]

for i in range(h):
    if i == 0:
        u[i,:]=grid[i,:]
    else:
        u[i,:]=(u[i-1,:]+1)*grid[i,:]
for i in range(h-1,-1,-1):
    if i==(h-1):
        d[i,:]=grid[i,:]
    else:
        d[i,:]=(d[i+1,:]+1)*grid[i,:]


ans=np.max(l+r+u+d-3)
print(ans)

Solution (Python):
import sys

H,W = list(map(int, input().split()))
S = [[]]*H

for h in range(H):
    S[h] = input()

T = [None]*W

for w in range(W):
    t = [S[h][w] for h in range(H)]
    T[w] = ''.join(t)





def calc_lights_map(MAP, H, W):
    LIGHTS_MAP = [None]*H
    for h in range(H):
        lights_map_row = calc_lights_map_row(MAP[h], W)
        LIGHTS_MAP[h] = lights_map_row
    return LIGHTS_MAP


def calc_lights_map_row(ROW, W):
    lights_map_row = []
    lights = 0
    for here, masu in enumerate(ROW):
        if masu == '
            lights_map_row.append(0)
            lights = 0
            continue
        if lights > 0:
            lights_map_row.append(lights)
            continue
        try:
            wall_id = ROW.index('
        except:
            wall_id = len(ROW)
        lights = wall_id - here
        lights_map_row.append(lights)
        continue
    return lights_map_row

S_lights_map = calc_lights_map(S, H, W)




T_lights_map = calc_lights_map(T, W, H)





max_lights = 0
for h in range(H):
    for w in range(W):
        lights = S_lights_map[h][w] + T_lights_map[w][h] - 1
        max_lights = max(max_lights, lights)


print(max_lights)

Solution (Python):

import numpy as np

def solve():
    H, W = list(map(int, input().split()))
    S = []
    for i in range(H):
        S.append(list(input()))
    grid = (np.array(S) == ".") * 1  

    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 j in range(W):
        if j==0:
            L[:,j] = grid[:,j]
        else:
            L[:,j] = (L[:,j-1]+1) * grid[:,j]
    
    for j in range(W-1, -1, -1):
        if j==(W-1):
            R[:,j] = grid[:,j]
        else:
            R[:,j] = (R[:,j+1] + 1) * grid[:, j]
    
    for i in range(H):
        if i==0:
            U[i,:] = grid[i,:]
        else:
            U[i,:] = (U[i-1,:]+1)*grid[i,:]
    
    for i in range(H-1, -1, -1):
        if i==(H-1):
            D[i,:] = grid[i,:]
        else:
            D[i,:] = (D[i+1,:]+1)*grid[i,:]
    
    ans = np.max(L+R+U+D-3)
    print(ans)

if __name__ == "__main__":
    solve()

Solution (Python):
import sys
from collections import deque, defaultdict
import copy
import bisect
input=sys.stdin.readline
sys.setrecursionlimit(10 ** 9)

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

num_yoko = [[0 for i in range(W)] for j in range(H)]
num_tate = [[0 for i in range(W)] for j in range(H)]

for i in range(H):
    for j in range(W):
        if grid[i][j] == '.':
            if j == 0:
                num_yoko[i][j] = 1
            else:
                num_yoko[i][j] = num_yoko[i][j - 1] + 1
            if i == 0:
                num_tate[i][j] = 1
            else:
                num_tate[i][j] = num_tate[i - 1][j] + 1
for i in range(H - 1, -1, -1):
    for j in range(W - 1, -1, -1):
        if grid[i][j] == '.':
            if j != W - 1:
                if num_yoko[i][j + 1] != 0:
                    num_yoko[i][j] = num_yoko[i][j + 1]
            if i != H - 1:
                if num_tate[i + 1][j] != 0:
                    num_tate[i][j] = num_tate[i + 1][j]

num_max = 0
for i in range(H):
    for j in range(W):
        if num_yoko[i][j] + num_tate[i][j] > num_max:
            num_max = num_yoko[i][j] + num_tate[i][j]


print(max(0, num_max - 1))