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 = [list(input()) for _ in range(H)]
SH = []
SW = []

for h in range(H):
    SW.append([])
    c = 0
    for w in range(W):
        if S[h][w] == '#':
            if c != 0:
                for _ in range(c):
                    SW[h].append(c)
            SW[h].append(0)
            c = 0
        else:
            c += 1
    for _ in range(c):
        SW[h].append(c)

for w in range(W):
    SH.append([])
    c = 0
    for h in range(H):
        if S[h][w] == '#':
            if c != 0:
                for _ in range(c):
                    SH[w].append(c)
            SH[w].append(0)
            c = 0
        else:
            c += 1
    for _ in range(c):
        SH[w].append(c)

ans = -1
for h in range(H):
    for w in range(W):
        ans = max(ans, SW[h][w] + SH[w][h] - 1)

print(ans)

Submission status: Time Limit Exceeded

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

field = [[[0, 0, 0, 0] for _ in range(W)] for __ in range(H)]

mx = 0
for i in range(H):
    for j in range(W):
        if S[i][j] == '.':
            # north
            if i == 0:
                field[i][j][0] = 1
            else:
                field[i][j][0] = field[i-1][j][0] + 1
            # west
            if j == 0:
                field[i][j][1] = 1
            else:
                field[i][j][1] = field[i][j-1][1] + 1
        k = H - 1 - i
        l = W - 1 - j
        if S[k][l] == '.':
            # east
            if l == W - 1:
                field[k][l][2] = 1
            else:
                field[k][l][2] = field[k][l+1][2] + 1
            # south
            if k == H - 1:
                field[k][l][3] = 1
            else:
                field[k][l][3] = field[k+1][l][3] + 1
        tmp1 = sum(field[i][j]) - 3
        tmp2 = sum(field[k][l]) - 3
        mx = max(mx, tmp1, tmp2)
print(mx)

Submission status: Time Limit Exceeded

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

field = [[{'n': 0, 'e': 0, 's': 0, 'w': 0} for _ in range(W)] for __ in range(H)]

mx = 0
for i in range(H):
    for j in range(W):
        if S[i][j] == '.':
            # north
            if i == 0:
                field[i][j]['n'] = 1
            else:
                field[i][j]['n'] = field[i-1][j]['n'] + 1
            # west
            if j == 0:
                field[i][j]['w'] = 1
            else:
                field[i][j]['w'] = field[i][j-1]['w'] + 1
        k = H - 1 - i
        l = W - 1 - j
        if S[k][l] == '.':
            # east
            if l == W - 1:
                field[k][l]['e'] = 1
            else:
                field[k][l]['e'] = field[k][l+1]['e'] + 1
            # south
            if k == H - 1:
                field[k][l]['s'] = 1
            else:
                field[k][l]['s'] = field[k+1][l]['s'] + 1
        tmp1 = sum(field[i][j].values()) - 3
        tmp2 = sum(field[k][l].values()) - 3
        mx = max(mx, tmp1, tmp2)
print(mx)

Submission status: Time Limit Exceeded

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

field = [[{'n': 0, 'e': 0, 's': 0, 'w': 0} for _ in range(W)] for __ in range(H)]

for i in range(H):
    for j in range(W):
        if S[i][j] == '.':
            # north
            if i == 0:
                field[i][j]['n'] = 1
            else:
                field[i][j]['n'] = field[i-1][j]['n'] + 1
            # west
            if j == 0:
                field[i][j]['w'] = 1
            else:
                field[i][j]['w'] = field[i][j-1]['w'] + 1
        k = H - 1 - i
        l = W - 1 - j
        if S[k][l] == '.':
            # east
            if l == W - 1:
                field[k][l]['e'] = 1
            else:
                field[k][l]['e'] = field[k][l+1]['e'] + 1
            # south
            if k == H - 1:
                field[k][l]['s'] = 1
            else:
                field[k][l]['s'] = field[k+1][l]['s'] + 1
mx = -1
for row in field:
    for x in row:
        sm = sum(x.values()) - 3
        if mx < sm:
            mx = sm
print(mx)

Submission status: Time Limit Exceeded

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

field = [[{'n': 0, 'e': 0, 's': 0, 'w': 0} for _ in range(W)] for __ in range(H)]

for i in range(H):
    for j in range(W):
        if S[i][j] == '#':
            continue
        # north
        if i == 0:
            field[i][j]['n'] = 1
        else:
            field[i][j]['n'] = field[i-1][j]['n'] + 1
        # west
        if j == 0:
            field[i][j]['w'] = 1
        else:
            field[i][j]['w'] = field[i][j-1]['w'] + 1
for i in range(H-1, -1, -1):
    for j in range(W-1, -1, -1):
        if S[i][j] == '#':
            continue
        # east
        if j == W - 1:
            field[i][j]['e'] = 1
        else:
            field[i][j]['e'] = field[i][j+1]['e'] + 1
        # south
        if i == H - 1:
            field[i][j]['s'] = 1
        else:
            field[i][j]['s'] = field[i+1][j]['s'] + 1
mx = -1
for row in field:
    for x in row:
        sm = sum(x.values()) - 3
        if mx < sm:
            mx = sm
print(mx)

Submission status: Time Limit Exceeded

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

field = [[{'n': 0, 'e': 0, 's': 0, 'w': 0} for _ in range(W)] for __ in range(H)]

for i in range(H):
    for j in range(W):
        if S[i][j] == '#':
            continue
        # north
        if i == 0:
            field[i][j]['n'] = 1
        else:
            field[i][j]['n'] = field[i-1][j]['n'] + 1
        # west
        if j == 0:
            field[i][j]['w'] = 1
        else:
            field[i][j]['w'] = field[i][j-1]['w'] + 1
for i in reversed(range(H)):
    for j in reversed(range(W)):
        if S[i][j] == '#':
            continue
        # east
        if j == W - 1:
            field[i][j]['e'] = 1
        else:
            field[i][j]['e'] = field[i][j+1]['e'] + 1
        # south
        if i == H - 1:
            field[i][j]['s'] = 1
        else:
            field[i][j]['s'] = field[i+1][j]['s'] + 1
mx = -1
for row in field:
    for x in row:
        sm = sum(x.values()) - 3
        if mx < sm:
            mx = sm
print(mx)

Submission status: Time Limit Exceeded

Solution code:
h, w = map(int, input().split())
s = [input() 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] == '.':
      if j == 0:
        l[i][j] = 1
      else:
        l[i][j] = l[i][j-1] + 1
    if s[i][w-j-1] == '.':
      if j == 0:
        r[i][w-j-1] = 1
      else:
        r[i][w-j-1] = r[i][w-j] + 1

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

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

Submission status: Time Limit Exceeded

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

ss = [input() for i in range(h)]
mp = [[]for i in range(h)]
for i in range(h):
    s = ss[i]
    prev = s[0]
    cnt = 0
    for j in range(w):
        if s[j]==prev: cnt+=1
        else:
            mp[i] += [cnt*(s[j]=="#")]*cnt
            cnt = 1
        prev = s[j]
    mp[i] += [cnt*(s[j]==".")]*cnt

ss = ["".join(i) for i in zip(*ss)]
pm = [[] for i in range(w)]
for i in range(w):
    s = ss[i]
    prev = s[0]
    cnt = 0
    for j in range(h):
        if s[j]==prev: cnt+=1
        else:
            pm[i] += [cnt*(s[j]=="#")]*cnt
            cnt = 1
        prev = s[j]
    pm[i] += [cnt*(s[j]==".")]*cnt

ans = 0
for i in range(h):
    for j in range(w):
        ans = max(ans, mp[i][j]+pm[j][i]-1)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
imput=sys.stdin.readline
h,w=map(int,input().split())
w+=2
h+=2
grid='#'*w
for _ in range(h-2):
    grid+='#'+input()+'#'
grid+='#'*w
move=[1,-1,w,-w]
score_a=[0]*(h*w)
score_b=[0]*(h*w)
score_c=[0]*(h*w)
score_d=[0]*(h*w)

for i in range(h*w):
    if grid[i]=='#':
        score_a[i]=0
        score_b[i]=0
    else:
        if i-1>=0 and i-1<=h*w-1:
            score_a[i]+=score_a[i-1]+1
        if i-w>=0 and i-w<=h*w-1:
            score_b[i]+=score_b[i-w]+1
    if grid[h*w-1-i]=='#':
        score_c[h*w-1-i]=0
        score_d[h*w-1-i]=0
    else:
        if h*w-1-i+1<=h*w-1 and h*w-1-i+1>=0:
            score_c[h*w-1-i]+=score_c[h*w-1-i+1]+1
        if h*w-1-i+w<=h*w-1 and h*w-1-i+w>=0:
            score_d[h*w-1-i]+=score_d[h*w-1-i+w]+1
ans=0
for i in range(h*w):
    ans=max(ans, score_a[i]+score_b[i]+score_c[i]+score_d[i]-3)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
h,w=map(int,input().split())
w+=2
h+=2
grid='#'*w
for _ in range(h-2):
    grid+='#'+input()+'#'
grid+='#'*w
move=[1,-1,w,-w]
score_a=[0]*(h*w)
score_b=[0]*(h*w)
score_c=[0]*(h*w)
score_d=[0]*(h*w)

for i in range(h*w):
    if grid[i]=='#':
        score_a[i]=0
        score_b[i]=0
    else:
        if i-1>=0 and i-1<=h*w-1:
            score_a[i]+=score_a[i-1]+1
        if i-w>=0 and i-w<=h*w-1:
            score_b[i]+=score_b[i-w]+1
    if grid[h*w-1-i]=='#':
        score_c[h*w-1-i]=0
        score_d[h*w-1-i]=0
    else:
        if h*w-1-i+1<=h*w-1 and h*w-1-i+1>=0:
            score_c[h*w-1-i]+=score_c[h*w-1-i+1]+1
        if h*w-1-i+w<=h*w-1 and h*w-1-i+w>=0:
            score_d[h*w-1-i]+=score_d[h*w-1-i+w]+1
ans=0
for i in range(h*w):
    ans=max(ans, score_a[i]+score_b[i]+score_c[i]+score_d[i]-3)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline


def main():
    H, W = map(int, input().split())
    s = [list(input()) for _ in range(H)]
    L = [[0] * W for _ in range(H)]
    R = [[0] * W for _ in range(H)]
    T = [[0] * W for _ in range(H)]
    B = [[0] * W for _ in range(H)]
    for h in range(H):
        for w in range(W):
            if s[h][w] == "#":
                R[h][w] = 0
            elif w == 0:
                R[h][w] = 1
            else:
                R[h][w] = R[h][w - 1] + 1
    for h in range(H):
        for w in reversed(range(W)):
            if s[h][w] == "#":
                L[h][w] = 0
            elif w == W - 1:
                L[h][w] = 1
            else:
                L[h][w] = L[h][w + 1] + 1
    for w in range(W):
        for h in range(H):
            if s[h][w] == "#":
                B[h][w] = 0
            elif h == 0:
                B[h][w] = 1
            else:
                B[h][w] = B[h-1][w] + 1
    for w in range(W):
        for h in reversed(range(H)):
            if s[h][w] == "#":
                T[h][w] = 0
            elif h == H - 1:
                T[h][w] = 1
            else:
                T[h][w] = T[h + 1][w] + 1
    ans = 0
    for h in range(H):
        for w in range(W):
            res = R[h][w] + L[h][w] + B[h][w] + T[h][w] - 3
            ans = max(ans, res)
    print(int(ans))


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
import sys
input = sys.stdin.readline


def main():
    H, W = map(int, input().split())
    s = [list(input()) for _ in range(H)]
    s = np.array(s)
    L = np.zeros((H, W))
    R = np.zeros((H, W))
    T = np.zeros((H, W))
    B = np.zeros((H, W))
    for h in range(H):
        for w in range(W):
            if s[h, w] == "#":
                R[h, w] = 0
            elif w == 0:
                R[h, w] = 1
            else:
                R[h, w] = R[h, w - 1] + 1
    for h in range(H):
        for w in reversed(range(W)):
            if s[h, w] == "#":
                L[h, w] = 0
            elif w == W - 1:
                L[h, w] = 1
            else:
                L[h, w] = L[h, w + 1] + 1
    for w in range(W):
        for h in range(H):
            if s[h, w] == "#":
                B[h, w] = 0
            elif h == 0:
                B[h, w] = 1
            else:
                B[h, w] = B[h-1, w] + 1
    for w in range(W):
        for h in reversed(range(H)):
            if s[h, w] == "#":
                T[h, w] = 0
            elif h == H - 1:
                T[h, w] = 1
            else:
                T[h, w] = T[h + 1, w] + 1
    ans = 0
    for h in range(H):
        for w in range(W):
            res = R[h, w] + L[h, w] + B[h, w] + T[h, w] - 3
            ans = max(ans, res)
    print(int(ans))


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
dx = [1, 0, -1, 0]
dy = [0, 1, 0, -1]


def main():
    H, W = map(int, input().split())
    s = [list(input()) for _ in range(H)]
    s = np.array(s)
    L = np.zeros((H, W))
    R = np.zeros((H, W))
    T = np.zeros((H, W))
    B = np.zeros((H, W))
    for h in range(H):
        for w in range(W):
            if s[h, w] == "#":
                R[h, w] = 0
            elif w == 0:
                R[h, w] = 1
            else:
                R[h, w] = R[h, w - 1] + 1
    for h in range(H):
        for w in reversed(range(W)):
            if s[h, w] == "#":
                L[h, w] = 0
            elif w == W - 1:
                L[h, w] = 1
            else:
                L[h, w] = L[h, w + 1] + 1
    for w in range(W):
        for h in range(H):
            if s[h, w] == "#":
                B[h, w] = 0
            elif h == 0:
                B[h, w] = 1
            else:
                B[h, w] = B[h-1, w] + 1
    for w in range(W):
        for h in reversed(range(H)):
            if s[h, w] == "#":
                T[h, w] = 0
            elif h == H - 1:
                T[h, w] = 1
            else:
                T[h, w] = T[h + 1, w] + 1
    ans = 0
    for h in range(H):
        for w in range(W):
            res = R[h, w] + L[h, w] + B[h, w] + T[h, w] - 3
            ans = max(ans, res)
    print(int(ans))


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
dx = [1, 0, -1, 0]
dy = [0, 1, 0, -1]


def main():
    H, W = map(int, input().split())
    s = [list(input()) for _ in range(H)]
    s = np.array(s)
    L = np.zeros((H, W))
    R = np.zeros((H, W))
    T = np.zeros((H, W))
    B = np.zeros((H, W))
    for h in range(H):
        for w in range(W):
            cnt = 0
            for v in s[h, w:]:
                if v == "#":
                    break
                cnt += 1
            R[h, w] = cnt
    for h in range(H):
        for w in range(W):
            cnt = 0
            for v in reversed(s[h, :w + 1]):
                if v == "#":
                    break
                cnt += 1
            L[h, w] = cnt
    for h in range(H):
        for w in range(W):
            cnt = 0
            for v in s[h:, w]:
                if v == "#":
                    break
                cnt += 1
            B[h, w] = cnt
    for h in range(H):
        for w in range(W):
            cnt = 0
            for v in reversed(s[:h + 1, w]):
                if v == "#":
                    break
                cnt += 1
            T[h, w] = cnt
    ans = 0
    for h in range(H):
        for w in range(W):
            res = R[h, w] + L[h, w] + B[h, w] + T[h, w] - 3
            ans = max(ans, res)
    print(int(ans))


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
H,W = map(int,input().split())
s = [list(input()) for i in range(H)]
sr = [i for i in zip(*s)]
right = [[0 for i in range(W)] for j in range(H)]
for h in range(H):
    r = [0 for i in range(W)]
    for w in range(W-1,-1,-1):
        if w== W-1:
            if s[h][w] == '.':
                right[h][w] = 1
        elif s[h][w] == '#':
            right[h][w] = 0
        else:
            right[h][w] = right[h][w+1]+1
left = [[0 for i in range(W)] for j in range(H)]
for h in range(H):
    for w in range(W):
        if w== 0:
            if s[h][w] == '.':
                left[h][w] = 1
        elif s[h][w] == '#':
            left[h][w] = 0
        else:
            left[h][w] = left[h][w-1]+1

up = [[0 for i in range(H)] for j in range(W)]
for w in range(W):
    for h in range(H):
        if h == 0:
            if sr[w][h] == '.':
                up[w][0] = 1
        elif sr[w][h] == '#':
            up[w][h] = 0
        else:
            up[w][h] = up[w][h-1]+1
down = [[0 for i in range(H)] for j in range(W)]
for w in range(W):
    for h in range(H-1,-1,-1):
        if h == H-1:
            if sr[w][h] == '.':
                down[w][h] = 1
        elif sr[w][h] == '#':
            down[w][h] = 0
        else:
            down[w][h] = down[w][h+1]+1
up = [i for i in zip(*up)]
down = [i for i in zip(*down)]

ans = 0
for h in range(H):
    for w in range(W):
        if s[h][w] == '.':
            ans = max(ans,right[h][w]+left[h][w]+up[h][w]+down[h][w]-3)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
H,W = map(int,input().split())
s = [list(input()) for i in range(H)]
sr = [i for i in zip(*s)]
right = []
for h in range(H):
    r = [0 for i in range(W)]
    for w in range(W-1,-1,-1):
        if w== W-1:
            if s[h][w] == '.':
                r[w] = 1
        elif s[h][w] == '#':
            r[w] = 0
        else:
            r[w] = r[w+1]+1
    right.append(tuple(r))
left = []
for h in range(H):
    l = [0 for i in range(W)]
    for w in range(W):
        if w== 0:
            if s[h][w] == '.':
                l[w] = 1
        elif s[h][w] == '#':
            l[w] = 0
        else:
            l[w] = l[w-1]+1
    left.append(tuple(l))
up = []
for w in range(W):
    u = [0 for i in range(H)]
    for h in range(H):
        if h == 0:
            if sr[w][h] == '.':
                u[0] = 1
        elif sr[w][h] == '#':
            u[h] = 0
        else:
            u[h] = u[h-1]+1
    up.append(tuple(u))
down = []
for w in range(W):
    d = [0 for i in range(H)]
    for h in range(H-1,-1,-1):
        if h == H-1:
            if sr[w][h] == '.':
                d[h] = 1
        elif sr[w][h] == '#':
            d[h] = 0
        else:
            d[h] = d[h+1]+1
    down.append(tuple(d))
up = [i for i in zip(*up)]
down = [i for i in zip(*down)]

ans = 0
for h in range(H):
    for w in range(W):
        if s[h][w] == '.':
            ans = max(ans,right[h][w]+left[h][w]+up[h][w]+down[h][w]-3)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
H,W = map(int,input().split())
s = [list(input()) for i in range(H)]
sr = [list(i) for i in zip(*s)]
right = []
for h in range(H):
    r = [0 for i in range(W)]
    for w in range(W-1,-1,-1):
        if w== W-1:
            if s[h][w] == '.':
                r[w] = 1
        elif s[h][w] == '#':
            r[w] = 0
        else:
            r[w] = r[w+1]+1
    right.append(r)
left = []
for h in range(H):
    l = [0 for i in range(W)]
    for w in range(W):
        if w== 0:
            if s[h][w] == '.':
                l[w] = 1
        elif s[h][w] == '#':
            l[w] = 0
        else:
            l[w] = l[w-1]+1
    left.append(l)
up = []
for w in range(W):
    u = [0 for i in range(H)]
    for h in range(H):
        if h == 0:
            if sr[w][h] == '.':
                u[0] = 1
        elif sr[w][h] == '#':
            u[h] = 0
        else:
            u[h] = u[h-1]+1
    up.append(u)
down = []
for w in range(W):
    d = [0 for i in range(H)]
    for h in range(H-1,-1,-1):
        if h == H-1:
            if sr[w][h] == '.':
                d[h] = 1
        elif sr[w][h] == '#':
            d[h] = 0
        else:
            d[h] = d[h+1]+1
    down.append(d)
up = [i for i in zip(*up)]
down = [i for i in zip(*down)]

ans = 0
for h in range(H):
    for w in range(W):
        if s[h][w] == '.':
            ans = max(ans,right[h][w]+left[h][w]+up[h][w]+down[h][w]-3)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
H,W = map(int,input().split())
s = [list(input()) for i in range(H)]
sr = [list(i) for i in zip(*s)]
def right(h,w):
    s2 = s[h][w:]
    count = 0
    for i in range(W-w):
        if s2[i] == '#':
            break
        else:
            count += 1
    return count
    
def left(h,w):
    s2 = s[h][:w+1]
    s2 = s2[::-1]
    count = 0
    for i in range(w+1):
        if s2[i] == '#':
            break
        else:
            count += 1
    return count
    
def up(h,w):
    s2 = sr[w][:h+1]
    s2 = s2[::-1]
    count = 0
    for i in range(h+1):
        if s2[i] == '#':
            break
        else:
            count += 1
    return count    
    
def down(h,w):
    s2 = sr[w][h:]
    count = 0
    for i in range(H-h):
        if s2[i] == '#':
            break
        else:
            count += 1
    return count    
    
    
ans = 0
for h in range(H):
    for w in range(W):
        if s[h][w] == '.':
            ans = max(ans,right(h,w)+left(h,w)+up(h,w)+down(h,w)-3)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline

def main():
    H,W = map(int,input().split())

    S = [[] for i in range(H)]

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

    M = 0
    for i in range(H):
        for j in range(W):
            cou = 0
            if S[i][j] == '.':
                for n in range(H-i-1):
                    if S[i+n+1][j] == '.':
                        cou += 1
                    else:
                        break
                if cou > i + cou + W:
                    break

                for n in range(W-j-1):
                    if S[i][j+n+1] == '.':
                        cou += 1
                    else:
                        break
                if cou > i + j + cou:
                    break

                for n in range(j):
                    if S[i][j-n-1] == '.':
                        cou += 1
                    else:
                        break
                if cou > j + cou:
                    break

                for n in range(i):
                    if S[i-n-1][j] == '.':
                        cou += 1
                    else:
                        break
            if cou > M:
                M = cou
                if M == H+W-2:
                    break

    print(M+1)

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline

def main():
    H,W = map(int,input().split())

    S = [[] for i in range(H)]

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

    M = 0
    for i in range(H):
        for j in range(W):
            cou = 0
            if S[i][j] == '.':
                for n in range(H-i-1):
                    if S[i+n+1][j] == '.':
                        cou += 1
                    else:
                        break
                if cou > i + cou + W:
                    break

                for n in range(W-j-1):
                    if S[i][j+n+1] == '.':
                        cou += 1
                    else:
                        break
                if cou > i + j + cou:
                    break

                for n in range(j):
                    if S[i][j-n-1] == '.':
                        cou += 1
                    else:
                        break
                if cou > j + cou:
                    break

                for n in range(i):
                    if S[i-n-1][j] == '.':
                        cou += 1
                    else:
                        break
            if cou > M:
                M = cou

    print(M+1)

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline

def main():
    H,W = map(int,input().split())

    S = [[] for i in range(H)]

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

    M = 0
    for i in range(H):
        for j in range(W):
            cou = 0
            if S[i][j] == '.':
                for n in range(i):
                    if S[i-n-1][j] == '.':
                        cou += 1
                    else:
                        break
                for n in range(H-i-1):
                    if S[i+n+1][j] == '.':
                        cou += 1
                    else:
                        break
                for n in range(j):
                    if S[i][j-n-1] == '.':
                        cou += 1
                    else:
                        break
                for n in range(W-j-1):
                    if S[i][j+n+1] == '.':
                        cou += 1
                    else:
                        break
            if cou > M:
                M = cou

    print(M+1)

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline

def main():
    H,W = map(int,input().split())

    S = [[] for i in range(H)]
    max = [[] for i in range(H)]

    for i in range(H):
        X = list(input())
        for j in range(W):
            S[i].insert(j,X[j])

    M = 0
    for i in range(H):
        for j in range(W):
            cou = 0
            if S[i][j] == '.':
                for n in range(i):
                    if S[i-n-1][j] == '.':
                        cou += 1
                    else:
                        break
                for n in range(H-i-1):
                    if S[i+n+1][j] == '.':
                        cou += 1
                    else:
                        break
                for n in range(j):
                    if S[i][j-n-1] == '.':
                        cou += 1
                    else:
                        break
                for n in range(W-j-1):
                    if S[i][j+n+1] == '.':
                        cou += 1
                    else:
                        break
            if cou > M:
                M = cou

    print(M+1)

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:

H, W = map(int, input().split())
S = ["#" * (W + 2)] + ["#" + input() + "#" for _ in range(H)] + ["#" * (W + 2)]

LEFT = [[0 for j in range(W+2)] for i in range(H+2)]
RIGHT = [[0 for j in range(W+2)] for i in range(H+2)]
UP = [[0 for j in range(W+2)] for i in range(H+2)]
DOWN = [[0 for j in range(W+2)] for i in range(H+2)]

for h in range(H+2):
  for w in range(W+2):
    if S[h][w] == ".":
      LEFT[h][w] = LEFT[h][w-1] + 1
    else:
      LEFT[h][w] = 0

for h in range(H+2):
  for w in range(W+2)[::-1]:
    if S[h][w] == ".":
      RIGHT[h][w] = RIGHT[h][w+1] + 1
    else:
      RIGHT[h][w] = 0

for h in range(H+2)[::-1]:
  for w in range(W+2):
    if S[h][w] == ".":
      UP[h][w] = UP[h+1][w] + 1
    else:
      UP[h][w] = 0

for h in range(H+2):
  for w in range(W+2):
    if S[h][w] == ".":
      DOWN[h][w] = DOWN[h-1][w] + 1
    else:
      DOWN[h][w] = 0

ans = -1

for h in range(H+2):
  for w in range(W+2):
    value = RIGHT[h][w] + LEFT[h][w] + UP[h][w] + DOWN[h][w] - 3
    ans = max(ans, value)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
h,w=map(int,input().split())
s=[input() for i in range(h)]
l=[[0]*w for i in range(h)]
r=[[0]*w for i in range(h)]
u=[[0]*w for i in range(h)]
d=[[0]*w for i 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 i in range(w):
  if s[0][i]=='.':
    u[0][i]=1
  if s[h-1][i]=='.':
    d[h-1][i]=1
for i in range(h):
  for j in range(w):
    if j>=1:
      if s[i][j]=='.':
        l[i][j]=l[i][j-1]+1
    if j<w-1:
      if s[i][w-j-2]=='.':
        r[i][w-j-2]=r[i][w-j-1]+1
    if i>=1:
      if s[i][j]=='.':
        u[i][j]=u[i-1][j]+1
    if i<h-1:
      if s[h-i-2][j]=='.':
        d[h-i-2][j]=d[h-i-1][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:
H, W=map(int, input().split())
S=[]
S.append("".join(["#" for _ in range(W+2)]))
S.extend(["#"+input()+"#" for _ in range(H)])
S.append("".join(["#" for _ in range(W+2)]))
co1=[[0 for _ in range(W+2)] for _ in range(H+2)]
co2=[[0 for _ in range(W+2)] for _ in range(H+2)]

for i in range(1, H+2):
    ppos=0
    for j in range(W+2):
        if S[i][j]=="#":
            if S[i][j-1]==".":
                for k in range(ppos, j):
                    co1[i][k]=j-ppos
            ppos=j+1

for j in range(1, W+2):
    ppos=0
    for i in range(H+2):
        if S[i][j]=="#":
            if S[i-1][j]==".":
                for k in range(ppos, i):
                    co2[k][j]=i-ppos
            ppos=i+1

ans=0
for i in range(1, H+2):
    for j in range(1, W+2):
        ans=max(ans, co1[i][j]+co2[i][j]-1)
print(ans)