Problem: 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.

Submission attempts (in order):
H,W = map(int,input().split())
S = []
for i in range(H):
    S += [['#'] + list(input()) + ['#']]
S = [['

ans,v = 0,[0 for i in range(W)]
for i in range(1,W+1):
    k = 1
    while S[k][i] == '.':
        k += 1
    v[i-1] = k - 1

for i in range(1,H+1):
    j,dot = 1,0
    while j < W+1:
        while S[i][j] == '.':
                dot += 1
                j += 1
        for k in range(j-dot,j):
            if ans < dot + v[k-1]:    ans = dot + v[k-1]

        dot = 0
        k = i+1
        if j < W+1:
            while S[k][j] == '.':
                k += 1
            v[j-1] = k - i - 1
            j += 1 
print(ans-1)    



H,W = map(int,input().split())
S = []
for i in range(H):
    S += [['#'] + list(input()) + ['#']]
S = [['

ans,v = 0,[0 for i in range(W)]
for i in range(1,W+1):
    k = 1
    while S[k][i] == '.':
        k += 1
    v[i-1] = k - 1

for i in range(1,H+1):
    dot = 1
    while S[i][dot] == '.':
            dot += 1
    dot -= 1
    for j in range(1,W+1):
        if S[i][j] == '#':
            k = j+1
            while S[i][k] == '.':
                k += 1
            dot = k - j - 1

            k = i+1
            while S[k][j] == '.':
                k += 1
            v[j-1] = k - i - 1 
        else:
            if ans < dot + v[j-1]:    ans = dot + v[j-1]
print(ans-1)    



H,W = map(int,input().split())
height, width_max, ans = [0] * (W+1), [0] * (W+1), 0
for i in range(H):
    s = input() + '#'
    length = 0
    for j in range(W+1):
        if s[j] == '.':
            length += 1
            height[j] += 1
        else:
            if length > 0:
                for k in range(j-length, j):
                    if width_max[k] < length:
                        width_max[k] = length
                length = 0
            if height[j] > 0:
                temp = width_max[j] + height[j] - 1
                if ans < temp:
                    ans = temp
                width_max[j], height[j] = 0, 0
for j in range(W):
    if height[j] > 0:
        temp = width_max[j] + height[j] - 1
        if ans < temp:
            ans = temp
print(ans)



Verdicts: Time Limit Exceeded

Time Limit Exceeded

Accepted