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 i in range(h)]
li=[[0,0] for i in range(h*w)]

for i in range(h):
    now=0
    for j in range(w):
        if li[i*w+j][0]!=0:
            continue
        elif s[i][j]=='.':
            now+=1
            if j==w-1:
                for k in range(j+1-now,j+1):
                    li[i*w+k][0]=now
                now=0
        else:
            for k in range(j-now,j):
                li[i*w+k][0]=now
            now=0

for i in range(w):
    now=0
    for j in range(h):
        if li[j*w+i][1]!=0:
            continue
        elif s[j][i]=='.':
            now+=1
            if j==h-1:
                for k in range(j+1-now,j+1):
                    li[k*w+i][1]=now
                now=0
        else:
            for k in range(j-now,j):
                li[k*w+i][1]=now
            now=0
    
ans=0    
for i in range(len(li)):
    ans=max(ans,sum(li[i]))
    
print(ans-1)

Submission status: Time Limit Exceeded

Solution code:
import sys
input=sys.stdin.readline
h,w=map(int,input().split())
s=[list(input()) for i in range(h)]
li=[[0,0] for i in range(h*w)]

for i in range(h):
    now=0
    for j in range(w):
        if li[i*w+j][0]!=0:
            continue
        elif s[i][j]=='.':
            now+=1
            if j==w-1:
                for k in range(j+1-now,j+1):
                    li[i*w+k][0]=now
                now=0
        else:
            for k in range(j-now,j):
                li[i*w+k][0]=now
            now=0

for i in range(w):
    now=0
    for j in range(h):
        if li[j*w+i][1]!=0:
            continue
        elif s[j][i]=='.':
            now+=1
            if j==h-1:
                for k in range(j+1-now,j+1):
                    li[k*w+i][1]=now
                now=0
        else:
            for k in range(j-now,j):
                li[k*w+i][1]=now
            now=0
    
ans=0    
for i in range(len(li)):
    ans=max(ans,sum(li[i]))
    
print(ans-1)

Submission status: Time Limit Exceeded

Solution code:
h,w=map(int,input().split())
s=[list(input()) for i in range(h)]
li=[[0,0] for i in range(h*w)]

for i in range(h):
    now=0
    for j in range(w):
        if li[i*w+j][0]!=0:
            continue
        elif s[i][j]=='.':
            now+=1
            if j==w-1:
                for k in range(j+1-now,j+1):
                    li[i*w+k][0]=now
                now=0
        else:
            for k in range(j-now,j):
                li[i*w+k][0]=now
            now=0

for i in range(w):
    now=0
    for j in range(h):
        if li[j*w+i][1]!=0:
            continue
        elif s[j][i]=='.':
            now+=1
            if j==h-1:
                for k in range(j+1-now,j+1):
                    li[k*w+i][1]=now
                now=0
        else:
            for k in range(j-now,j):
                li[k*w+i][1]=now
            now=0
    
ans=0    
for i in range(len(li)):
    ans=max(ans,sum(li[i]))
    
print(ans-1)

Submission status: Time Limit Exceeded

Solution code:
H,W = (int(i) for i in input().split())
S = [0] * H
for i in range(H):
    S[i] = list(input())

x = [] * W
y = [] * H
L = [[1]*W for i in range(H)]
R = [[1]*W for i in range(H)]
U = [[1]*W for i in range(H)]
D = [[1]*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
            U[i][j] = 0
        elif i == 0 and j == 0:
            continue
        elif i == 0:
            L[i][j] = L[i][j-1] + 1
        elif j == 0:
            U[i][j] = U[i-1][j] + 1
        else:
            L[i][j] = L[i][j-1] + 1
            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
        elif i == H-1 and j == W-1:
            continue
        elif i == H-1:
            R[i][j] = R[i][j+1] + 1
        elif j == W-1:
            D[i][j] = D[i+1][j] + 1
        else:
            R[i][j] = R[i][j+1] + 1
            D[i][j] = D[i+1][j] + 1

for i in range(H):
    for j in range(W):
        tmp = L[i][j] + R[i][j] + D[i][j] + U[i][j] - 3
        if tmp > ans:
            ans = tmp

print(ans)

Submission status: Time Limit Exceeded

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

for i in range(H):
  for j in reversed(range(W)):
      if S[i][j]=='.':
        R[i][j]=R[i][j+1]+1 if j!=W-1 else 1
      else:
        R[i][j]=0
#print(R)

for j in range(W):
  for i in range(H):
      if S[i][j]=='.':
        U[i][j]=U[i-1][j]+1 if i!=0 else 1
      else:
        U[i][j]=0
#print(U)

for j in range(W):
  for i in reversed(range(H)):
      if S[i][j]=='.':
        D[i][j]=D[i+1][j]+1 if i!=H-1 else 1
      else:
        D[i][j]=0
#print(D)

for i in range(H):
  for j in range(W):
    A[i][j]=L[i][j]+R[i][j]+D[i][j]+U[i][j]-3

res = -1
for i in range(H):
  res = max(res,max(A[i]))
print(res)

Submission status: Time Limit Exceeded

Solution code:
H, W = map(int, input().split())
L = []
for i in range(H):
	s = list(input())
	s_list = [i for i, x in enumerate(s) if x == '#']
	l = []
	last = -1
	for j in s_list:
		l += [j - last - 1] * (j - last - 1) + [0]
		last = j
	l += [W - last - 1] * (W - last - 1)
	L.append(l)
for i in range(W):
	count = 0
	for j in range(H):
		if L[j][i] == 0:
			for k in range(count):
				L[j - k - 1][i] += count
			count = 0
		else:
			count += 1
	for k in range(count):
		L[H - k - 1][i] += count			
ans = 0
for i in range(H):
	ans = max(max(L[i]) - 1, ans)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
H,W = map(int,input().split())
S = [input().strip() for _ in range(H)]
Srow = [[] for _ in range(H)]
for i in range(H):
    cur = 0
    cnt = 0
    for j in range(W):
        if S[i][j]!="#":
            cnt += 1
        else:
            Srow[i].append((cur,j,cnt))
            cnt = 0
            cur = j+1
    if S[i][W-1]!="#":
        Srow[i].append((cur,W,cnt))
Scol = [[] for _ in range(W)]
for j in range(W):
    cur = 0
    cnt = 0
    for i in range(H):
        if S[i][j]!="#":
            cnt += 1
        else:
            Scol[j].append((cur,i,cnt))
            cnt = 0
            cur = i+1
    if S[H-1][j]!="#":
        Scol[j].append((cur,H,cnt))
A = [[0 for _ in range(W)] for _ in range(H)]
for i in range(H):
    for x in Srow[i]:
        s,e,cnt = x[0],x[1],x[2]
        for j in range(s,e):
            A[i][j] = cnt
for j in range(W):
    for y in Scol[j]:
        s,e,cnt = y[0],y[1],y[2]
        for i in range(s,e):
            A[i][j] += cnt
cmax = 0
for i in range(H):
    for j in range(W):
        cmax = max(cmax,A[i][j])
print(cmax-1)

Submission status: Time Limit Exceeded

Solution code:
H,W=map(int,input().split())
A=[list(map(lambda x:False if x=='#' else True ,input())) for i in range(H)]

L=[[0]*W for i in range(H)]
R=[[0]*W for i in range(H)]
D=[[0]*W for i in range(H)]
U=[[0]*W for i in range(H)]


for i in range(H):
	for j in range(1,W):
		if A[i][j]:
			L[i][j]=int(A[i][j-1])+L[i][j-1]

for i in range(H):
	for j in range(W-1)[::-1]:
		if A[i][j]:
			R[i][j]=int(A[i][j+1])+R[i][j+1]

for i in range(1,H):
	for j in range(W):
		if A[i][j]:
			U[i][j]=int(A[i-1][j])+U[i-1][j]


for i in range(H-1)[::-1]:
	for j in range(W):
		if A[i][j]:
			D[i][j]=int(A[i+1][j])+D[i+1][j]

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]+1)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter,defaultdict
import sys,heapq,bisect,math,itertools,string,queue
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())

h,w = inpl()
s = [[0] * w for i in range(h)]
r = [[0] * w for i in range(h)]
l = [[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):
    s[i] = input()

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

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter,defaultdict
import sys,heapq,bisect,math,itertools,string,queue
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())

h,w = inpl()
s = [[0] * w for i in range(h)]
ss = [[0] * w for i in range(h)]
st = [[0] * w for i in range(h)]
for i in range(h):
    s[i] = input()

for i in range(h):
    cnt = 0
    start = w
    end = w
    for j in range(w)[::-1]:
        if s[i][j] == '.':
            cnt += 1
            start = j
        else:
            for k in range(start,end):
                ss[i][k] = cnt
            cnt = 0
            end = j
        if cnt > 0:
            for k in range(start,end):
                ss[i][k] = cnt
for i in range(w):
    cnt = 0
    start = h
    end = h
    for j in range(h)[::-1]:
        if s[j][i] == '.':
            cnt += 1
            start = j
        else:
            for k in range(start,end):
                st[k][i] = cnt
            cnt = 0
            end = j
        if cnt > 0:
            for k in range(start,end):
                st[k][i] = cnt
ans = 0
for i in range(h):
    for j in range(w):
        ans = max(ans, ss[i][j] + st[i][j])
print(ans-1)

Submission status: Time Limit Exceeded

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

def main():
    H, W = map(int, input().split())
    s = [list(input().strip()) for i in range(H)]

    left = [[0] * W for i in range(H)]
    right = [[0] * W for i in range(H)]
    up = [[0] * W for i in range(H)]
    down = [[0] * W for i in range(H)]

    for i in range(H):
        count = 0
        for j in range(W):
            if s[i][j] == ".":
                count += 1
                left[i][j] = count
            else:
                count = 0
                left[i][j] = count
        count = 0
        for j in range(W-1, -1, -1):
            if s[i][j] == ".":
                count += 1
                right[i][j] = count
            else:
                count = 0
                right[i][j] = count

    for j in range(W):
        count = 0
        for i in range(H):
            if s[i][j] == ".":
                count += 1
                down[i][j] = count
            else:
                count = 0
                down[i][j] = count
        count = 0
        for i in range(H-1, -1, -1):
            if s[i][j] == ".":
                count += 1
                up[i][j] = count
            else:
                count = 0
                up[i][j] = count
    
    ans = 0
    for i in range(H):
        for j in range(W):
            ans = max(ans, left[i][j] + right[i][j] + up[i][j] + down[i][j] - 3)
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

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

yoko=[[0]*2005 for _ in range(2005)]
tate=[[0]*2005 for _ in range(2005)]

for i in range(h):
	for j in range(w):
		if s[i][j] == ".":
			yoko[i][j]+=1
			if j>0:
				yoko[i][j]+=yoko[i][j-1]
	for j in range(w-2,-1,-1):
		yoko[i][j] = max(yoko[i][j],yoko[i][j+1]) if yoko[i][j] else 0

for j in range(w):
	for i in range(h):
		if s[i][j] == ".":
			tate[i][j]+=1
			if i>0:
				tate[i][j]+=tate[i-1][j]
	for i in range(h-2,-1,-1):
		tate[i][j] = max(tate[i][j],tate[i+1][j])  if tate[i][j] else 0

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

Submission status: Time Limit Exceeded

Solution code:
h,w = map(int,input().split())
list1 = []
list2 = []

for i in range(w):
  list2.append([])

for i in range(h):
  s = input()
  list1.append(s)
  for j in range(w):
    list2[j].append(s[j])

list3 = []
for i in range(h):
  list3.append([])
  
list4 = []
for i in range(w):
  list4.append([])

for i in range(h):
  tmp_list = list1[i].split('#')
  for tmp in tmp_list:
    leng = len(tmp)
    list3[i].extend([leng]*leng)
    list3[i].append(0)
    
for i in range(w):
  tmp_list = (''.join(list2[i])).split('#')
  for tmp in tmp_list:
    leng = len(tmp)
    list4[i].extend([leng]*leng)
    list4[i].append(0)
    
max_num = -1
for i in range(w):
  for j in range(h):
    list3[j][i] += list4[i][j]-1
    max_num = max(max_num, list3[j][i])
    
print(max_num)

Submission status: Time Limit Exceeded

Solution code:
#coding utf-8
import numpy as np
H,W=map(int,input().split())
S= [list(input().strip()) for _ in range(H)]

left  =np.array([[0 for i in range(W)]for i in range(H)])
right =np.array([[0 for i in range(W)]for i in range(H)])
up    =np.array([[0 for i in range(W)]for i in range(H)])
down  =np.array([[0 for i in range(W)]for i in range(H)])

for i in range(H):
  for j in range(W):
    if S[i][j]==".":
      if j ==0:
        left[i][j]=1
      else:
        left[i][j]=left[i][j-1]+1
      if i==0:
        up[i][j]=1
      else:
        up[i][j]=up[i-1][j]+1
    else:
      left[i][j]=0
      up[i][j]=0
     
for i in range(H-1,-1,-1):
  for j in range(W-1,-1,-1):
    if S[i][j]==".":
      if j ==W-1:
        right[i][j]=1
      else:
        right[i][j]=right[i][j+1]+1
      if i==H-1:
        down[i][j]=1
      else:
        down[i][j]=down[i+1][j]+1
    else:
      right[i][j]=0
      down[i][j]=0

ans=up+down+left+right-np.array([[3 for i in range(W)] for i in range(H)])      
print(ans.max())

Submission status: Time Limit Exceeded

Solution code:
#coding utf-8
import numpy as np
H,W=map(int,input().split())
S= [list(input().strip()) for _ in range(H)]

left  =np.array([[0 for i in range(W)]for i in range(H)])
right =np.array([[0 for i in range(W)]for i in range(H)])
up    =np.array([[0 for i in range(W)]for i in range(H)])
down  =np.array([[0 for i in range(W)]for i in range(H)])

for i in range(H):
  for j in range(W):
    if S[i][j]==".":
      if j ==0:
        left[i][j]=1
      else:
        left[i][j]=left[i][j-1]+1
    else:
      left[i][j]=0
     
for i in range(H):
  for j in range(W-1,-1,-1):
    if S[i][j]==".":
      if j ==W-1:
        right[i][j]=1
      else:
        right[i][j]=right[i][j+1]+1
    else:
      right[i][j]=0      

for j in range(W):
  for i in range(H):
    if S[i][j]==".":
      if i==0:
        up[i][j]=1
      else:
        up[i][j]=up[i-1][j]+1
    else:
      up[i][j]=0   
 
for j in range(W):
  for i in range(H-1,-1,-1):
    if S[i][j]==".":
      if i==H-1:
        down[i][j]=1
      else:
        down[i][j]=down[i+1][j]+1
    else:
      down[i][j]=0

ans=up+down+left+right-np.array([[3 for i in range(W)] for i in range(H)])      
print(ans.max())

Submission status: Time Limit Exceeded

Solution code:
#21:10
h,w = map(int,input().split())
raw = []
for x in range(h):
  raw.append(input())
xx = []
for x in range(h):
  now = []
  tmp = 0
  for y in range(w):
    if raw[x][y] == '.':
      tmp += 1
    else:
      now += [tmp] * tmp
      tmp = 0
      now.append(0)
  now += [tmp] * tmp
  xx.append(now)
yy = []
for y in range(w):
  now = []
  tmp = 0
  for x in range(h):
    if raw[x][y] == '.':
      tmp += 1
    else:
      now += [tmp] * tmp
      tmp = 0
      now.append(0)
  now += [tmp] * tmp
  yy.append(now)
'''
for x in range(h):
  print(xx[x])
for y in range(w):
  print(yy[y])
'''
maxi = 0
for x in range(h):
  for y in range(w):
    maxi = max(maxi,xx[x][y]+yy[y][x]-1)
print(maxi)

Submission status: Time Limit Exceeded

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


def main():
    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)]
    ans = 0
    for i in range(h):
        for j in range(w):
            if j != 0:
                L[i][j] = L[i][j - 1]
            if s[i][j] == ".":
                L[i][j] += 1
            else:
                L[i][j] = 0
    for i in range(h):
        for j in range(w - 1, -1, -1):
            if j != w - 1:
                R[i][j] = R[i][j + 1]
            if s[i][j] == ".":
                R[i][j] += 1
            else:
                R[i][j] = 0
    for j in range(w):
        for i in range(h):
            if i != 0:
                U[i][j] = U[i - 1][j]
            if s[i][j] == ".":
                U[i][j] += 1
            else:
                U[i][j] = 0
    for j in range(w):
        for i in range(h - 1, -1, -1):
            if i != h - 1:
                D[i][j] = D[i + 1][j]
            if s[i][j] == ".":
                D[i][j] += 1
            else:
                D[i][j] = 0
    for i in range(h):
        for j in range(w):
            if s[i][j] == ".":
                ans = max(ans, L[i][j] + R[i][j] + U[i][j] + D[i][j] - 3)
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
def main():
    h, w = map(int, input().split())
    s = [tuple(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)]
    ans = 0
    for i in range(h):
        for j in range(w):
            if j != 0:
                L[i][j] = L[i][j - 1]
            if s[i][j] == ".":
                L[i][j] += 1
            else:
                L[i][j] = 0
    for i in range(h):
        for j in range(w - 1, -1, -1):
            if j != w - 1:
                R[i][j] = R[i][j + 1]
            if s[i][j] == ".":
                R[i][j] += 1
            else:
                R[i][j] = 0
    for j in range(w):
        for i in range(h):
            if i != 0:
                U[i][j] = U[i - 1][j]
            if s[i][j] == ".":
                U[i][j] += 1
            else:
                U[i][j] = 0
    for j in range(w):
        for i in range(h - 1, -1, -1):
            if i != h - 1:
                D[i][j] = D[i + 1][j]
            if s[i][j] == ".":
                D[i][j] += 1
            else:
                D[i][j] = 0
    for i in range(h):
        for j in range(w):
            if s[i][j] == ".":
                ans = max(ans, L[i][j] + R[i][j] + U[i][j] + D[i][j] - 3)
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
def main():
    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)]
    ans = 0
    for i in range(h):
        for j in range(w):
            if j != 0:
                L[i][j] = L[i][j - 1]
            if s[i][j] == ".":
                L[i][j] += 1
            else:
                L[i][j] = 0
    for i in range(h):
        for j in range(w - 1, -1, -1):
            if j != w - 1:
                R[i][j] = R[i][j + 1]
            if s[i][j] == ".":
                R[i][j] += 1
            else:
                R[i][j] = 0
    for j in range(w):
        for i in range(h):
            if i != 0:
                U[i][j] = U[i - 1][j]
            if s[i][j] == ".":
                U[i][j] += 1
            else:
                U[i][j] = 0
    for j in range(w):
        for i in range(h - 1, -1, -1):
            if i != h - 1:
                D[i][j] = D[i + 1][j]
            if s[i][j] == ".":
                D[i][j] += 1
            else:
                D[i][j] = 0
    for i in range(h):
        for j in range(w):
            if s[i][j] == ".":
                ans = max(ans, L[i][j] + R[i][j] + U[i][j] + D[i][j] - 3)
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
h,w = map(int,input().split())
M = []
for i in range(h):
    M.append(input())
L = []
R = []
U = []
D = []
Total = []
for i in range(h):
    s = [0]*w
    L.append(s)
for i in range(h):
    s = [0]*w
    R.append(s)
for i in range(h):
    s = [0]*w
    U.append(s)
for i in range(h):
    s = [0]*w
    D.append(s)
for i in range(h):
    s = [0]*w
    Total.append(s)
for i in range(h):
    for j in range(w):
        if M[i][j] == '#':
            None
        else:
            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 M[i][j] == '#':
            None
        else:
            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 M[i][j] == '#':
            None
        else:
            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):
        if M[i][j] == '#':
            None
        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[i][j] += L[i][j]+R[i][j]+U[i][j]+D[i][j]-3
ans = 0
for i in range(h):
    for j in range(w):
        if Total[i][j] > ans:
            ans = Total[i][j]
print(ans)

Submission status: Time Limit Exceeded

Solution code:
h,w = map(int,input().split(" "))
s = [[0 for i in range(w)] for j in range(h)]
for i in range(h):
    tmp = list(input())
    for j in range(w):
        s[i][j] = tmp[j]

dp1= []
dp2= [[-1 for i in range(w)] for j in range(h)]
dp3=[]
dp4=[[-1 for i in range(w)] for j in range(h)]


for i in range(h):
    dp1.append([])
    dp3.append([])
    for j in range(w):
        dp1[i].append(-1)
        dp3[i].append(-1)

        if s[i][j] == "#":
            dp1[i][j] = 0
        elif j == 0:
            dp1[i][j] = 1
        else:
            dp1[i][j] = 1 + dp1[i][j-1]

        if s[i][w-j-1] == "#":
            dp2[i][w-j-1] = 0
        elif w-j-1 == w-1:
            dp2[i][w-j-1] = 1
        else:
            dp2[i][w-j-1] = 1 + dp2[i][w-j]

        if s[i][j] == "#":
            dp3[i][j] = 0
        elif i == 0:
            dp3[i][j] = 1
        else:
            dp3[i][j] = 1 + dp3[i-1][j]

        if s[h-i-1][j] == "#":
            dp4[h-i-1][j] = 0
        elif h-i-1 == h-1:
            dp4[h-i-1][j] = 1
        else:
            dp4[h-i-1][j] = 1 + dp4[h-i][j]



        

a = 1
for i in range(h):
    for j in range(w):
        a = max(a,dp1[i][j]+dp2[i][j]+dp3[i][j]+dp4[i][j]-3)


print(a)

Submission status: Time Limit Exceeded

Solution code:
h,w = map(int,input().split(" "))
s = [[0 for i in range(w)] for j in range(h)]
for i in range(h):
    tmp = list(input())
    for j in range(w):
        s[i][j] = tmp[j]

dp1= []
dp2= [[-1 for i in range(w)] for j in range(h)]
dp3=[]
dp4=[]


for i in range(h):
    dp1.append([])
    dp3.append([])
    dp4.append([])
    for j in range(w):
        dp1[i].append(-1)
        dp3[i].append(-1)
        dp4[i].append(-1)

        if s[i][j] == "#":
            dp1[i][j] = 0
        elif j == 0:
            dp1[i][j] = 1
        else:
            dp1[i][j] = 1 + dp1[i][j-1]

        if s[i][w-j-1] == "#":
            dp2[i][w-j-1] = 0
        elif w-j-1 == w-1:
            dp2[i][w-j-1] = 1
        else:
            dp2[i][w-j-1] = 1 + dp2[i][w-j]



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

        if s[h-j-1][i] == "#":
            dp4[h-j-1][i] = 0
        elif h-j-1 == h-1:
            dp4[h-j-1][i] = 1
        else:
            dp4[h-j-1][i] = 1 + dp4[h-j][i]


a = 1
for i in range(h):
    for j in range(w):
        a = max(a,dp1[i][j]+dp2[i][j]+dp3[i][j]+dp4[i][j]-3)


print(a)

Submission status: Time Limit Exceeded

Solution code:
h,w = map(int,input().split(" "))
s = [[0 for i in range(w)] for j in range(h)]
for i in range(h):
    tmp = list(input())
    for j in range(w):
        s[i][j] = tmp[j]

dp1= []
dp2= []
dp3=[]
dp4=[]
for i in range(h):
    dp1.append([])
    dp2.append([])
    dp3.append([])
    dp4.append([])
    for j in range(w):
        dp1[i].append(-1)
        dp2[i].append(-1)
        dp3[i].append(-1)
        dp4[i].append(-1)

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

        if s[h-j-1][i] == "#":
            dp4[h-j-1][i] = 0
        elif h-j-1 == h-1:
            dp4[h-j-1][i] = 1
        else:
            dp4[h-j-1][i] = 1 + dp4[h-j][i]


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

        if s[i][w-j-1] == "#":
            dp2[i][w-j-1] = 0
        elif w-j-1 == w-1:
            dp2[i][w-j-1] = 1
        else:
            dp2[i][w-j-1] = 1 + dp2[i][w-j]
a = 1
for i in range(h):
    for j in range(w):
        a = max(a,dp1[i][j]+dp2[i][j]+dp3[i][j]+dp4[i][j]-3)


print(a)

Submission status: Time Limit Exceeded

Solution code:
h,w = map(int,input().split(" "))
s = [[0 for i in range(w)] for j in range(h)]
for i in range(h):
    tmp = list(input())
    for j in range(w):
        s[i][j] = tmp[j]

dp1= []
dp2= []
dp3=[]
dp4=[]
for i in range(h):
    dp1.append([])
    dp2.append([])
    dp3.append([])
    dp4.append([])
    for j in range(w):
        dp1[i].append(-1)
        dp2[i].append(-1)
        dp3[i].append(-1)
        dp4[i].append(-1)






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

        if s[h-j-1][i] == "#":
            dp4[h-j-1][i] = 0
        elif h-j-1 == h-1:
            dp4[h-j-1][i] = 1
        else:
            dp4[h-j-1][i] = 1 + dp4[h-j][i]


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

        if s[i][w-j-1] == "#":
            dp2[i][w-j-1] = 0
        elif w-j-1 == w-1:
            dp2[i][w-j-1] = 1
        else:
            dp2[i][w-j-1] = 1 + dp2[i][w-j]
a = 1
for i in range(h):
    for j in range(w):
        a = max(a,dp1[i][j]+dp2[i][j]+dp3[i][j]+dp4[i][j]-3)


print(a)

Submission status: Time Limit Exceeded

Solution code:
h,w = map(int,input().split(" "))
s = [[0 for i in range(w)] for j in range(h)]
for i in range(h):
    tmp = list(input())
    for j in range(w):
        s[i][j] = tmp[j]

dp1 = [[-1 for i in range(w)] for j in range(h)]
dp2 = [[-1 for i in range(w)] for j in range(h)]
dp3 = [[-1 for i in range(w)] for j in range(h)]
dp4 = [[-1 for i in range(w)] for j in range(h)]





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

        if s[h-j-1][i] == "#":
            dp4[h-j-1][i] = 0
        elif h-j-1 == h-1:
            dp4[h-j-1][i] = 1
        else:
            dp4[h-j-1][i] = 1 + dp4[h-j][i]


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

        if s[i][w-j-1] == "#":
            dp2[i][w-j-1] = 0
        elif w-j-1 == w-1:
            dp2[i][w-j-1] = 1
        else:
            dp2[i][w-j-1] = 1 + dp2[i][w-j]
a = 1
for i in range(h):
    for j in range(w):
        a = max(a,dp1[i][j]+dp2[i][j]+dp3[i][j]+dp4[i][j]-3)


print(a)