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

M = [[[0, 0] for i in range(W)] for j in range(H)]
V = [[[False, False] for i in range(W)] for j in range(H)]


def search(grid, h, w, H, W, V_lst):
    h_cnt = 0
    v_cnt = 0

    if w != W and not V_lst[1]:
        for _ in range(W):
            if grid[h][w + h_cnt] != '#':
                h_cnt += 1
                if w + h_cnt == W:
                    break

    if h != H and not V_lst[0]:
        for _ in range(H):
            if grid[h + v_cnt][w] != '#':
                v_cnt += 1
                if h + v_cnt == H:
                    break

    return h_cnt, v_cnt

for h in range(H):
    for w in range(W):
        if grid[h][w] == '#':
            continue
        else:
            h_cnt, v_cnt = search(grid, h, w, H, W, V[h][w])

            for i in range(h_cnt):
                V[h][w + i][1] = True
                M[h][w + i][1] = h_cnt - 1

            for i in range(v_cnt):
                V[h + i][w][0] = True
                M[h + i][w][0] = v_cnt - 1

m = -1
for h in range(H):
    for w in range(W):
        if M[h][w][0] + M[h][w][1] > m:
            m = M[h][w][0] + M[h][w][1] + 1

print(m)

Submission status: Time Limit Exceeded

Solution code:
h,w=map(int, input().split())
s=[[0 for _ in range(w)] for _ in range(h)]
for j in range(h):
    s[j]=list(input())
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)]
max=0

for i in range(h):
    for j in range(w):
        if s[i][j]=='#':
            l[i][j]=0
            u[i][j]=0
        else:
            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-1,-1,-1):
    for j in range(w-1,-1,-1):
        if s[i][j]=='#':
            r[i][j]=0
            d[i][j]=0
        else:
            if j==w-1:
                r[i][j]=1
            else:
                r[i][j]=r[i][j+1]+1
            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):        
        total=l[i][j]+r[i][j]+d[i][j]+u[i][j]

        if max<total:
            max=total

print(max-3)

Submission status: Time Limit Exceeded

Solution code:
def main():
    h, w = list(map(int, input().split()))
    grid = []
    for _ in range(h):
        grid.append(input())

    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 grid[i][j] == '#':
                continue
            if j == 0:
                L[i][j] = 1
            else:
                L[i][j] = L[i][j - 1] + 1

    for i in range(h):
        for j in range(w - 1, -1, -1):
            if grid[i][j] == '#':
                continue
            if j == w - 1:
                R[i][j] = 1
            else:
                R[i][j] = R[i][j + 1] + 1

    for j in range(w):
        for i in range(h):
            if grid[i][j] == '#':
                continue
            if i == 0:
                D[i][j] = 1
            else:
                D[i][j] = D[i - 1][j] + 1

    for j in range(w):
        for i in range(h - 1, -1, -1):
            if grid[i][j] == '#':
                continue
            if i == h - 1:
                U[i][j] = 1
            else:
                U[i][j] = U[i + 1][j] + 1

    score = 0
    for i in range(h):
        for j in range(w):
            score = max(score, L[i][j] + R[i][j] + D[i][j] + U[i][j] - 3)

    print(score)


main()

Submission status: Time Limit Exceeded

Solution code:
h,w=map(int, input().split())
s=[[0 for _ in range(w)] for _ in range(h)]
for j in range(h):
    s[j]=list(input())
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)]
max=0

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 j in range(w):
    for i in range(h):
        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-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

for j in range(w):
    for i in range(h-1,-1,-1):
        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):        
        total=l[i][j]+r[i][j]+d[i][j]+u[i][j]

        if max<total:
            max=total

print(max-3)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
h,w=map(int,input().split())
s = [list(map(int,list(input().replace('#','1').replace('.','0')))) for i in range(h)]
s = np.array(s)
yoko=np.zeros((h,w))
tate=np.zeros((h,w))
yoko2=np.zeros((h,w))
tate2=np.zeros((h,w))
for i in range(h):
  tmp=0
  for j in range(w):
    if s[i,j]==1:
      tmp=0
    else:
      tmp+=1
    yoko[i,j]=tmp
for j in range(w):
  tmp=0
  for i in range(h):
    if s[i,j]==1:
      tmp=0
    else:
      tmp+=1
    tate[i,j]=tmp

for i in range(h):
  for j in range(w-1,-1,-1):
    if yoko[i,j]==0 or j==w-1:
      tmp = 0
    tmp=max(tmp,yoko[i,j])
    yoko2[i,j]=tmp

for j in range(w):
  for i in range(h-1,-1,-1):
    if tate[i,j]==0 or i==h-1:
      tmp=0
    tmp=max(tmp,tate[i,j])
    tate2[i,j]=tmp

print(int(np.amax(yoko2+tate2)-1))

Submission status: Time Limit Exceeded

Solution code:
h,w=map(int,input().split())
s = [list(map(int,list(input().replace('#','1').replace('.','0')))) for i in range(h)]
ans=0
for i in range(h):
  for j in range(w):
    if s[i][j]==0:
      cnt=0
      tmp_i=i
      tmp_j=j
      while 0<=i:
        if i==h:
          cnt+=i-tmp_i
          break
        elif s[i][j] == 1:
          cnt+=i-tmp_i
          break
        else:
          i+=1
      i=tmp_i
      while i<h:
        if i<0:
          cnt+=tmp_i - i
          break
        elif s[i][j] == 1:
          cnt+=tmp_i - i
          break
        else:
          i-=1
      i=tmp_i
      while 0<=j:
        if j==w:
          cnt+=j-tmp_j
          break
        elif s[i][j] == 1:
          cnt+=j-tmp_j
          break
        else:
          j+=1
      j=tmp_j
      while j<w:
        if j<0:
          cnt+=tmp_j - j
          break
        elif s[i][j] == 1:
          cnt+=tmp_j - j
          break
        else:
          j-=1
      j=tmp_j
      ans=max(ans,cnt)
print(ans-3)

Submission status: Time Limit Exceeded

Solution code:
import sys
h,w=map(int,input().split())
s = [list(map(int,list(input().replace('#','1').replace('.','0')))) for i in range(h)]
ans=0
for i in range(h):
  for j in range(w):
    if s[i][j]==0:
      cnt=0
      tmp_i=i
      tmp_j=j
      while 0<=i:
        if i==h:
          cnt+=abs(tmp_i - i)
          break
        elif s[i][j] == 1:
          cnt+=abs(tmp_i - i)
          break
        else:
          i+=1
      i=tmp_i
      while i<h:
        if i<0:
          cnt+=abs(tmp_i - i)
          break
        elif s[i][j] == 1:
          cnt+=abs(tmp_i - i)
          break
        else:
          i-=1
      i=tmp_i
      while 0<=j:
        if j==w:
          cnt+=abs(tmp_j - j)
          break
        elif s[i][j] == 1:
          cnt+=abs(tmp_j - j)
          break
        else:
          j+=1
      j=tmp_j
      while j<w:
        if j<0:
          cnt+=abs(tmp_j - j)
          break
        elif s[i][j] == 1:
          cnt+=abs(tmp_j - j)
          break
        else:
          j-=1
      j=tmp_j
      ans=max(ans,cnt)
print(ans-3)

Submission status: Time Limit Exceeded

Solution code:
#import numpy as np

h,w=map(int,input().split())
s = [list(input()) for i in range(h)]
#s = np.array(s)
ans=0
for i in range(h):
  for j in range(w):
    if s[i][j]=='.':
      cnt=0
      tmp_i=i
      tmp_j=j
      while 0<=i:
        if i==h:
          cnt+=abs(tmp_i - i)
          break
        elif s[i][j] == '#':
          cnt+=abs(tmp_i - i)
          break
        else:
          i+=1
      i=tmp_i
      while i<h:
        if i<0:
          cnt+=abs(tmp_i - i)
          break
        elif s[i][j] == '#':
          cnt+=abs(tmp_i - i)
          break
        else:
          i-=1
      i=tmp_i
      while 0<=j:
        if j==w:
          cnt+=abs(tmp_j - j)
          break
        elif s[i][j] == '#':
          cnt+=abs(tmp_j - j)
          break
        else:
          j+=1
      j=tmp_j
      while j<w:
        if j<0:
          cnt+=abs(tmp_j - j)
          break
        elif s[i][j] == '#':
          cnt+=abs(tmp_j - j)
          break
        else:
          j-=1
      j=tmp_j
      ans=max(ans,cnt)
print(ans-3)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

h,w=map(int,input().split())
s = [list(input()) for i in range(h)]
s = np.array(s)
ans=0
for i in range(h):
  for j in range(w):
    if s[i,j]=='.':
      cnt=0
      tmp_i=i
      tmp_j=j
      while 0<=i:
        if i==h:
          cnt+=abs(tmp_i - i)
          break
        elif s[i,j] == '#':
          cnt+=abs(tmp_i - i)
          break
        else:
          i+=1
      i=tmp_i
      while i<h:
        if i<0:
          cnt+=abs(tmp_i - i)
          break
        elif s[i,j] == '#':
          cnt+=abs(tmp_i - i)
          break
        else:
          i-=1
      i=tmp_i
      while 0<=j:
        if j==w:
          cnt+=abs(tmp_j - j)
          break
        elif s[i,j] == '#':
          cnt+=abs(tmp_j - j)
          break
        else:
          j+=1
      j=tmp_j
      while j<w:
        if j<0:
          cnt+=abs(tmp_j - j)
          break
        elif s[i,j] == '#':
          cnt+=abs(tmp_j - j)
          break
        else:
          j-=1
      j=tmp_j
      ans=max(ans,cnt)
print(ans-3)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

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

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

right = np.array([[0] * W for i in range(H)])
for i in range(H):
    c = -1
    for j in range(W-1, -1, -1):
        if S[i][j] == '#':
            c = -1
        else:
            c += 1
        right[i][j] = c

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

down = np.array([[0] * W for i in range(H)])
for j in range(W):
    c = -1
    for i in range(H-1, -1, -1):
        if S[i][j] == '#':
            c = -1
        else:
            c += 1
        down[i][j] = c

n_all = right+left+up+down
print(np.max(n_all)+1)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

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

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

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

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

down = [[0] * W for i in range(H)]
for j in range(W):
    c = -1
    for i in range(H-1, -1, -1):
        if S[i][j] == '#':
            c = -1
        else:
            c += 1
        down[i][j] = c

n_right = np.array(right)
n_left = np.array(left)
n_up = np.array(up)
n_down = np.array(down)

n_all = n_right+n_left+n_up+n_down
print(np.max(n_all)+1)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
h,w=map(int,input().split())
s = [list(input()) for i in range(h)]
s = np.array(s)
yoko=np.zeros((h,w))
tate=np.zeros((h,w))
yoko2=np.zeros((h,w))
tate2=np.zeros((h,w))
for i in range(h):
  tmp=0
  for j in range(w):
    if s[i,j]=='#':
      tmp=0
    else:
      tmp+=1
    yoko[i,j]=tmp
for j in range(w):
  tmp=0
  for i in range(h):
    if s[i,j]=='#':
      tmp=0
    else:
      tmp+=1
    tate[i,j]=tmp

for i in range(h):
  for j in range(w-1,-1,-1):
    if yoko[i,j]==0 or j==w-1:
      tmp = 0
    tmp=max(tmp,yoko[i,j])
    yoko2[i,j]=tmp

for j in range(w):
  for i in range(h-1,-1,-1):
    if tate[i,j]==0 or i==h-1:
      tmp=0
    tmp=max(tmp,tate[i,j])
    tate2[i,j]=tmp

print(int(np.amax(yoko2+tate2)-1))

Submission status: Time Limit Exceeded

Solution code:
h, w = map(int, input().split())
s = [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)]

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

m = 0
for i in range(h):
    for j in range(w):
        k = l[i][j] + r[i][j] + u[i][j] + d[i][j] - 3
        if k > m:
            m = k

print(m)

Submission status: Time Limit Exceeded

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

s = [list(input()) for i in range(h)]

left = [[0 for i in range(w)] for j in range(h)]
right = [[0 for i in range(w)] for j in range(h)]
up = [[0 for i in range(w)] for j in range(h)]
down = [[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] == '#':
            left[i][j] = 0
        elif j == 0:
            left[i][j] = 1
        else:
            left[i][j] = left[i][j-1] + 1
        if s[i][w-j-1] == '#':
            right[i][w-j-1] = 0
        elif j == 0:
            right[i][w-j-1] = 1
        else:
            right[i][w-j-1] = right[i][w-j] + 1

for j in range(w):
    for i in range(h):
        if s[i][j] == '#':
            up[i][j] = 0
        elif i == 0:
            up[i][j] = 1
        else:
            up[i][j] = up[i-1][j] + 1
        if s[h-i-1][j] == '#':
            down[h-i-1][j] = 0
        elif i == 0:
            down[h-i-1][j] = 1
        else:
            down[h-i-1][j] = down[h-i][j] + 1

ans = [[0 for i in range(w)] for j in range(h)]
for i in range(h):
    for j in range(w):
        ans[i][j] = up[i][j] + right[i][j] + down[i][j] + left[i][j] - 3

max = -3
for i in range(h):
    for j in range(w):
        if max < ans[i][j]:
            max = ans[i][j]

print(max)

Submission status: Time Limit Exceeded

Solution code:
h, w = map(int, input().split())
s = [list(input()) for i in range(h)]
flag = [[False] * w for i in range(h)]
for i in range(h):
    for j in range(w):
        flag[i][j] = s[i][j] == "."
a = [[0] * w for i in range(h)]
for i in range(h):
    count = 0
    for j in range(w):
        if flag[i][j]:
            count += 1
            a[i][j] = count
        else:
            count = 0
for i in range(h - 1, -1, -1):
    m = 0
    for j in range(w - 1, -1, -1):
        if flag[i][j]:
            if m:
                a[i][j] = m
            else:
                m = a[i][j]
        else:
            m = 0
b = [[0] * w for i in range(h)]
for j in range(w):
    count = 0
    for i in range(h):
        if flag[i][j]:
            count += 1
            b[i][j] = count
        else:
            count = 0
for j in range(w - 1, -1, -1):
    m = 0
    for i in range(h - 1, -1, -1):
        if flag[i][j]:
            if m:
                b[i][j] = m
            else:
                m = b[i][j]
        else:
            m = 0
ans = 0
for i in range(h):
    for j in range(w):
        ans = max(ans, a[i][j] + b[i][j] - 1)
print(ans)

Submission status: Time Limit Exceeded

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

for i in range(h):
  tmp = input()
  s.append(tmp)

#左にいくつあるか
l = [[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] == "#":
      l[i][j] = 0
    else:
      if j == 0:
        l[i][j] = 1
        continue
      l[i][j] = l[i][j-1] + 1
#print(l)
      
#上
d = [[0 for i in range(w)] for j in range(h)]

for j in range(w):
  for i in range(h):
    if s[i][j] == "#":
      d[i][j] = 0
    else:
      if i == 0:
        d[i][j] = 1
        continue
      d[i][j] = d[i-1][j] + 1  
#print(d)      

#右にいくつあるか
r = [[0 for i in range(w)] for j in range(h)]

for i in range(h):
  for j in range(w)[::-1]:
#    print(i,j)
    if s[i][j] == "#":
      r[i][j] = 0
    else:
      if j == w-1:
#        print("aa")
        r[i][j] = 1
        continue
      r[i][j] = r[i][j+1] + 1
      
#print(r)

#下
u = [[0 for i in range(w)] for j in range(h)]

for j in range(w):
  for i in range(h)[::-1]:
    if s[i][j] == "#":
      u[i][j] = 0
    else:
      if i == h-1:
        u[i][j] = 1
        continue
      u[i][j] = u[i+1][j] + 1

#print(u)


#足し合わせ
for i in range(h):
  for j in range(w):
    l[i][j] += r[i][j] + u[i][j] + d[i][j] -3

   
import numpy as np
l = np.array(l)
#print(l)
print(l.max())

Submission status: Time Limit Exceeded

Solution code:
H, W = map(int, input().split())
S = [list(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)]
LAMP = [[0]*W for i in range(H)]
ans = 0
for i in range(H):
  for j in range(W):
    if S[i][j] == "#":
      L[i][j] = 0
    elif j == 0:
      L[i][j] = 1
    else:
      L[i][j] = L[i][j-1] + 1
    if S[i][j] == "#":
      U[i][j] = 0
    elif i == 0:
      U[i][j] = 1
    else:
      U[i][j] = U[i-1][j] + 1
      
for i in range(H-1,-1,-1):
  for j in range(W-1,-1,-1):
    if S[i][j] == "#":
      R[i][j] = 0
    elif j == W-1:
      R[i][j] = 1
    else:
      R[i][j] = R[i][j+1] + 1
    if S[i][j] == "#":
      D[i][j] = 0
    elif i == H-1:
      D[i][j] = 1
    else:
      D[i][j] = D[i+1][j] + 1
    if S[i][j] != "#":
       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())

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)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
import sys
import numpy as np

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

# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    H = int(next(tokens))  # type: int
    W = int(next(tokens))  # type: int
    S = [ next(tokens) for _ in range(H) ]  # type: "List[str]"
    solve(H, W, S)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
import sys
import numpy as np

def solve(H: int, W: int, S: "List[str]"):
    L = np.zeros((H, W))
    R = np.zeros((H, W))
    U = np.zeros((H, W))
    D = np.zeros((H, W))
    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))

# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    H = int(next(tokens))  # type: int
    W = int(next(tokens))  # type: int
    S = [ next(tokens) for _ in range(H) ]  # type: "List[str]"
    solve(H, W, S)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
import sys
import numpy as np

def solve(H: int, W: int, S: "List[str]"):
    L = np.zeros((H, W))
    R = np.zeros((H, W))
    U = np.zeros((H, W))
    D = np.zeros((H, W))
    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
    for i in range(H):
        for j in reversed(range(W)):
            if S[i][j] != '#':
                if j == W-1:
                    R[i, j] = 1
                else:
                    R[i, j] = R[i, j+1] + 1
    for i in range(H):
        for j in range(W):
            if S[i][j] != '#':
                if i == 0:
                    D[i, j] = 1
                else:
                    D[i, j] = D[i-1, j] + 1
    for i in reversed(range(H)):
        for j in range(W):
            if S[i][j] != '#':
                if i == H-1:
                    U[i, j] = 1
                else:
                    U[i, j] = U[i+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))

# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    H = int(next(tokens))  # type: int
    W = int(next(tokens))  # type: int
    S = [ next(tokens) for _ in range(H) ]  # type: "List[str]"
    solve(H, W, S)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
import sys
import numpy as np

def solve(H: int, W: int, S: "List[str]"):
    for i in range(H):
        for j in range(W):
            pass
    L = np.zeros((H, W))
    R = np.zeros((H, W))
    U = np.zeros((H, W))
    D = np.zeros((H, W))
    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
    for i in range(H):
        for j in reversed(range(W)):
            if S[i][j] != '#':
                if j == W-1:
                    R[i, j] = 1
                else:
                    R[i, j] = R[i, j+1] + 1
    for i in range(H):
        for j in range(W):
            if S[i][j] != '#':
                if i == 0:
                    D[i, j] = 1
                else:
                    D[i, j] = D[i-1, j] + 1
    for i in reversed(range(H)):
        for j in range(W):
            if S[i][j] != '#':
                if i == H-1:
                    U[i, j] = 1
                else:
                    U[i, j] = U[i+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))

# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    H = int(next(tokens))  # type: int
    W = int(next(tokens))  # type: int
    S = [ next(tokens) for _ in range(H) ]  # type: "List[str]"
    solve(H, W, S)

if __name__ == '__main__':
    main()