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:
import numpy as np
import copy as cp

h,w = map(int,input().split())

# 題意のリストを0,1で入力
arr = [0 for i in range(h)]
for i in range(h):
    s = input()
    tmp = list(s)
    for j in range(w):
        tmp[j] = 0 if tmp[j]=="#" else 1
    arr[i] = tmp

left = cp.deepcopy(arr)
right = cp.deepcopy(arr)
up = cp.deepcopy(arr)
down = cp.deepcopy(arr)

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

# right
for i in range(h):
    for j in range(w-1,-1,-1):
        if j==w-1 : continue
        if right[i][j] == 0 : continue
        right[i][j] += right[i][j+1]

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

# down
for i in range(w):
    for j in range(h-1,-1,-1):
        if j==h-1 : continue
        if down[j][i] == 0 : continue
        down[j][i] += down[j+1][i]

# 答えを求める
ans = 0
for i in range(h):
    for j in range(w):
        val = left[i][j] + right[i][j] + up[i][j] + down[i][j] - 3
        ans = max(ans, val)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
import copy as cp

h,w = map(int,input().split())

# 題意のリストを0,1で入力
arr = [0 for i in range(h)]
for i in range(h):
    s = input()
    tmp = list(s)
    for j in range(w):
        tmp[j] = 0 if tmp[j]=="#" else 1
    arr[i] = tmp

arr = np.array(arr, dtype=np.int64)
left = cp.deepcopy(arr)
right = cp.deepcopy(arr)
up = cp.deepcopy(arr)
down = cp.deepcopy(arr)

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

# right
for i in range(h):
    for j in range(w-1,-1,-1):
        if j==w-1 : continue
        if right[i][j] == 0 : continue
        right[i][j] += right[i][j+1]

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

# down
for i in range(w):
    for j in range(h-1,-1,-1):
        if j==h-1 : continue
        if down[j][i] == 0 : continue
        down[j][i] += down[j+1][i]

# 答えを求める
ans = 0
for i in range(h):
    for j in range(w):
        val = left[i][j] + right[i][j] + up[i][j] + down[i][j] - 3
        ans = max(ans, val)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
import copy as cp

h,w = map(int,input().split())

# 題意のリストを0,1で入力
arr = [0 for i in range(h)]
for i in range(h):
    s = input()
    tmp = list(s)
    for j in range(w):
        tmp[j] = 0 if tmp[j]=="#" else 1
    arr[i] = tmp

arr = np.array(arr, dtype=np.int64)
left = cp.deepcopy(arr)
right = cp.deepcopy(arr)
up = cp.deepcopy(arr)
down = cp.deepcopy(arr)

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

# right
for i in range(h):
    for j in range(w-1,-1,-1):
        if j==w-1 : continue
        if right[i][j] == 0 : continue
        right[i][j] += right[i][j+1]

# up
up = up.T
for i in range(w):
    for j in range(h):
        if j==0 : continue
        if up[i][j] == 0 : continue
        up[i][j] += up[i][j-1]
up = up.T

# down
down = down.T
for i in range(w):
    for j in range(h-1,-1,-1):
        if j==h-1 : continue
        if down[i][j] == 0 : continue
        down[i][j] += down[i][j+1]
down = down.T

# 答えを求める
ans = 0
for i in range(h):
    for j in range(w):
        val = left[i][j] + right[i][j] + up[i][j] + down[i][j] - 3
        ans = max(ans, val)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
import copy as cp

h,w = map(int,input().split())

# 題意のリストを
arr = [0 for i in range(h)]
for i in range(h):
    s = input()
    tmp = list(s)
    for j in range(w):
        tmp[j] = 0 if tmp[j]=="#" else 1
    arr[i] = tmp

arr = np.array(arr)
left = cp.deepcopy(arr)
right = cp.deepcopy(arr)
up = cp.deepcopy(arr)
down = cp.deepcopy(arr)

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

# right
for i in range(h):
    for j in range(w-1,-1,-1):
        if j==w-1 : continue
        if right[i][j] == 0 : continue
        right[i][j] += right[i][j+1]

# up
up = up.T
for i in range(w):
    for j in range(h):
        if j==0 : continue
        if up[i][j] == 0 : continue
        up[i][j] += up[i][j-1]
up = up.T

# down
down = down.T
for i in range(w):
    for j in range(h-1,-1,-1):
        if j==h-1 : continue
        if down[i][j] == 0 : continue
        down[i][j] += down[i][j+1]
down = down.T

# 答えを求める
ans = 0
for i in range(h):
    for j in range(w):
        val = left[i][j] + right[i][j] + up[i][j] + down[i][j] - 3
        ans = max(ans, val)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
H, W = map(int, input().split())
S = [list(input()) + ['_'] for _ in range(H)]
S.append(['_'] * (W+1))

x_seq = [[0] * W for _ in range(H)]
y_seq = [[0] * W for _ in range(H)]

for k in range(H):
    left = 0
    right = 0
    seq = 0
    for i in range(W+1):
        if S[k][i] == '.':
            seq += 1
            right = i+1
        else:
            for j in range(left, right):
                x_seq[k][j] = seq
            seq = 0
            left = i+1
            right = i+1

for k in range(W):
    up = 0
    down = 0
    seq = 0
    for i in range(H+1):
        if S[i][k] == '.':
            seq += 1
            down = i+1
        else:
            for j in range(up, down):
                y_seq[j][k] = seq
            seq = 0
            up = down = i+1

grid = [[0] * W for _ in range(H)]
for i in range(H):
    for j in range(W):
        grid[i][j] = x_seq[i][j] + y_seq[i][j]
print(max([max(x) for x in grid]) - 1)

Submission status: Time Limit Exceeded

Solution code:
H,W = map(int,input().split())
# pdding around the map with '#'
Map = [['#']*(W+2)]
for i in range(H):
  Map += [list('#' + input() + '#')]
Map += [['#']*(W+2)]
cnt_arr = []
def search(h,w):
  cnt = 0
  # search up
  nh,nw = h,w
  for _ in range(H+2):
    if Map[nh-1][nw]=='.':
      nh -= 1
      cnt += 1
    else:
      break
  # search down
  nh,nw = h,w
  for _ in range(H+2):
    if Map[nh+1][nw]=='.':
      nh += 1
      cnt += 1
    else:
      break
  # search left
  nh,nw = h,w
  for _ in range(W+2):
    if Map[nh][nw-1]=='.':
      nw -= 1
      cnt += 1
    else:
      break
  # search right
  nh,nw = h,w
  for _ in range(W+2):
    if Map[nh][nw+1]=='.':
      nw += 1
      cnt += 1
    else:
      break

  return cnt+1

for h in range(H):
  for w in range(W):
    if Map[h+1][w+1] == '.':
      cnt_arr.append(search(h+1,w+1))
print(max(cnt_arr))

Submission status: Time Limit Exceeded

Solution code:
h,w=map(int,input().split())
lists=[]
for i in range(h):
    s=input()
    lists.append(s)
ylists=[]
for some in lists:
    some=some+"#"
    cnt=0
    add=[]
    for i in range(w+1):
        if some[i]=="#":
            if cnt==0:
                add.append(0)
                cnt=0
            else:
                add.extend([cnt]*cnt)
                add.append(0)
                cnt=0
                
        elif some[i]!="#":
            cnt+=1
    del add[-1]
    ylists.append(add)
lists1=[]
for i in range(w):
    adds=""
    for j in range(h):
        adds+=lists[j][i]
    lists1.append(adds)
    

tlists=[]
for some in lists1:
    some=some+"#"
    cnt=0
    add=[]
    for i in range(h+1):
        if some[i]=="#":
            if cnt==0:
                add.append(0)
                cnt=0
            else:
                add.extend([cnt]*cnt)
                add.append(0)
                cnt=0
                
        elif some[i]!="#":
            cnt+=1
    del add[-1]
    tlists.append(add)


listss=[]
for i in range(h):
    for j in range(w):
        if ylists[i][j]==0 or  tlists[j][i]==0:
            continue
        else:
            listss.append(ylists[i][j]+tlists[j][i]-1)
print(max(listss))

Submission status: Time Limit Exceeded

Solution code:
h,w=map(int,input().split())
lists=[]
for i in range(h):
    s=input()
    lists.append(s)
ylists=[]
for some in lists:
    some=some+"#"
    cnt=0
    add=[]
    for i in range(w+1):
        if some[i]=="#":
            if cnt==0:
                add.append(0)
                cnt=0
            else:
                add.extend([cnt]*cnt)
                add.append(0)
                cnt=0
                
        elif some[i]!="#":
            cnt+=1
    del add[-1]
    ylists.append(add)
    

            
lists1=[]
for i in range(w):
    adds=""
    for j in range(h):
        adds+=lists[j][i]
    lists1.append(adds)
    
tlists=[]
for some in lists1:
    some=some+"#"
    cnt=0
    add=[]
    for i in range(h+1):
        if some[i]=="#":
            if cnt==0:
                add.append(0)
                cnt=0
            else:
                add.extend([cnt]*cnt)
                add.append(0)
                cnt=0
                
        elif some[i]!="#":
            cnt+=1
    del add[-1]
    tlists.append(add)


maximum=0
for i in range(h):
    for j in range(w):
        if ylists[i][j]==0 or tlists[j][i]==0:
            continue
        else:
            maximum=max(maximum,ylists[i][j]+tlists[j][i]-1)
print(maximum)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

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

S = np.array(S)
S = np.where(S=='#',1,0) #0は空間、1は壁

def Lcount(u,v):
    if S[u][v]==1:
        return(0)
    else:
        score=1
        ue,sita,migi,hida = 1,1,1,1
        while S[u-ue][v]==0:
            score+=1
            ue+=1
        while S[u+sita][v]==0:
            score+=1
            sita+=1
        while S[u][v+migi]==0:
            score+=1
            migi+=1
        while S[u][v-hida]==0:
            score+=1
            hida+=1
        return(score)

p=0
for i in range(H):
    for j in range(W):
        L=Lcount(i+1,j+1)
        p=max(L,p)
        if L==W+H-1:
            break

print(p)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

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

S = np.array(S)
S = np.where(S=='#',1,0) #0は空間、1は壁

def Lcount(u,v):
    if S[u][v]==1:
        return(0)
    else:
        score=1
        ue,sita,migi,hida = 1,1,1,1
        while S[u-ue][v]==0:
            score+=1
            ue+=1
        while S[u+sita][v]==0:
            score+=1
            sita+=1
        while S[u][v+migi]==0:
            score+=1
            migi+=1
        while S[u][v-hida]==0:
            score+=1
            hida+=1
        return(score)

A=[]
for i in range(H):
    for j in range(W):
        A.append(Lcount(i+1,j+1))

print(max(A))

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

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

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

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

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

print(ans)

Submission status: Time Limit Exceeded

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

y,x = [0,0]
le = [[[0,0] for i in range(w)] for j in range(h)]
ans = 0
while x < w and y < h:
    if s[y][x] == "." or 0 in le[y][x]:
        x1 = x
        xlength = 0
        while not  x >= w and s[y][x] == ".":
            x += 1
            xlength += 1

        for xindex in range(x1, x):
            le[y][xindex][1] = xlength
            y1 = y
            ylength = 0
            if le[y][xindex][0] == 0:
                while not y1 >= h and s[y1][xindex] == ".":
                    y1 += 1
                    ylength += 1
                for yindex in range(y, y1):
                    le[yindex][xindex][0] = ylength

        if x < w-1:
            x += 1
        else:
            x = 0
            y += 1
    else:
        if x < w-1:
            x += 1
        else:
            x = 0
            y += 1

for i in le:
    for j in i:
        sumj = sum(j)
        if all(j):
            sumj -= 1
        ans = max(ans, sumj)

print(ans)

Submission status: Time Limit Exceeded

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

e=[[0 for i in range(w)] for j in range(h)]
r=[[0 for i in range(w)] for j in range(h)]
l=[[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)]


for i in range(h):
  for j in range(w):
    if s[i][j]=='.':
      e[i][j] = 1

for i in range(h):
  l[i][0] = e[i][0]
  r[i][w-1] = e[i][w-1]
  for j in range(1,w):
    l[i][j] = (l[i][j-1]+1) * e[i][j]
    r[i][w-j-1] = (r[i][w-j]+1) * e[i][w-j-1]

for i in range(w):
  u[0][i]=e[0][i]
  d[h-1][i]=e[h-1][i]
  for j in range(1,h):
    u[j][i] = (u[j-1][i]+1) * e[j][i]
    d[h-j-1][i] = (d[h-j][i]+1) * e[h-j-1][i]

m = 0
for i in range(h):
   for j in range(w):
      m = max(m,l[i][j]+r[i][j]+u[i][j]+d[i][j])

print(m-3)

Submission status: Time Limit Exceeded

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

e=[[0 for i in range(w)] for j in range(h)]
r=[[0 for i in range(w)] for j in range(h)]
l=[[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)]


for i in range(h):
  for j in range(w):
    if s[i][j]=='.':
      e[i][j] = 1

for i in range(h):
  l[i][0] = e[i][0]
  for j in range(1,w):
    l[i][j] = (l[i][j-1]+1) * e[i][j]
  r[i][w-1] = e[i][w-1]
  for j in range(w-1,0,-1):
    r[i][j-1] = (r[i][j]+1) * e[i][j-1]

for i in range(w):
  u[0][i]=e[0][i]
  for j in range(1,h):
    u[j][i] = (u[j-1][i]+1) * e[j][i]
  d[h-1][i]=e[h-1][i]
  for j in range(h-1,0,-1):
    d[j-1][i] = (d[j][i]+1) * e[j-1][i]

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

print(m)

Submission status: Time Limit Exceeded

Solution code:
H,W=[int(s) for s in input().split()]
lamp=[input() for _ in range(H)]
#Lを計算
L=[[0 for _ in range(W)] for _ in range(H)]
for i in range(H):
  if lamp[i][0]=="#" :  L[i][0]=0
  else: L[i][0]=1
  for j in range(1,W):
    if lamp[i][j]=="#" : L[i][j]=0
    else: L[i][j]=L[i][j-1]+1
#Rを計算
R=[[0 for _ in range(W)] for _ in range(H)]
for i in range(H):
  if lamp[i][W-1]=="#" :  R[i][W-1]=0
  else: R[i][W-1]=1
  for j in range(1,W):
    if lamp[i][W-1-j]=="#" : R[i][W-1-j]=0
    else: R[i][W-1-j]=R[i][W-j]+1
#Uを計算
U=[[0 for _ in range(W)] for _ in range(H)]
for j in range(W):
  if lamp[0][j]=="#" :  U[0][j]=0
  else: U[0][j]=1
  for i in range(1,H):
    if lamp[i][j]=="#" : U[i][j]=0
    else: U[i][j]=U[i-1][j]+1
#Dを計算
D=[[0 for _ in range(W)] for _ in range(H)]
for j in range(W):
  if lamp[H-1][j]=="#" :  D[H-1][j]=0
  else: D[H-1][j]=1
  for i in range(1,H):
    if lamp[H-1-i][j]=="#" : D[H-1-i][j]=0
    else: D[H-1-i][j]=D[H-i][j]+1
ls=[]
for i in range(H):
  for j in range(W):
    ls.append(L[i][j]+R[i][j]+U[i][j]+D[i][j]-3)
print(max(ls))

Submission status: Time Limit Exceeded

Solution code:
h, w = [int(i) for i in input().split()]
a = []
b = [""] * w
for _ in range(h):
    s = input()
    a.append(s)
    for i, j in enumerate(s):
        b[i] += j


def c(s):
    m = 0
    n = 0
    for i in s:
        if i == ".":
            n += 1
        else:
            m = max(n, m)
            n=0
    m = max(n, m)
    return m


print(c(max(a, key=c)) + c(max(b, key=c)) - 1)

Submission status: Time Limit Exceeded

Solution code:
h, w = [int(i) for i in input().split()]
a = []
b = [""] * w
for _ in range(h):
    s = input()
    a.append(s)
    for i, j in enumerate(s):
        b[i] += j


def c(s):
    m = 0
    n = 0
    for i in s:
        if i == ".":
            n += 1
            m = max(n, m)
        else:
            n = 0
    return m


print(c(max(a, key=c)) + c(max(b, key=c)) - 1)

Submission status: Time Limit Exceeded

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

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 j in range(H):
  for i in range(W):
    if field[j][i]==".":
      if i==0:
        l[j][i]=1
      else:
        l[j][i]=l[j][i-1]+1
      if j==0:
        u[j][i]=1
      else:
        u[j][i]=u[j-1][i]+1
        

for j in reversed(range(H)):
  for i in reversed(range(W)):
    if field[j][i]==".":
      if i==W-1:
        r[j][i]=1
      else:
        r[j][i]=r[j][i+1]+1
      if j==H-1:
        d[j][i]=1
      else:
        d[j][i]=d[j+1][i]+1

A=[]
for j in range(H):
  for i in range(W):
    A.append(l[j][i]+r[j][i]+d[j][i]+u[j][i]-3)

print(max(A))

Submission status: Time Limit Exceeded

Solution code:
H,W=map(int,input().split())
g=[[True for j in range(W)] for i in range(H)] # 障害物がなければTrue
for i in range(H):
    S=input()
    for j in range(W):
        if S[j]=='#':
            g[i][j]=False
D=[[0 for j in range(W)] for i in range(H)]
U=[[0 for j in range(W)] for i in range(H)]
R=[[0 for j in range(W)] for i in range(H)]
L=[[0 for j in range(W)] for i in range(H)]

for i in range(H):
    for j in range(W):
        if g[i][j]:
            if j==0:
                L[i][j]=1
            else:
                L[i][j]=L[i][j-1]+1
    for j in reversed(range(W)):
        if g[i][j]:
            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 g[i][j]:
            if i==0:
                U[i][j]=1
            else:
                U[i][j]=U[i-1][j]+1
    for i in reversed(range(H)):
        if g[i][j]:
            if i==H-1:
                D[i][j]=1
            else:
                D[i][j]=D[i+1][j]+1

ans=0

for i in range(H):
    for j in range(W):
        if g[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())
g=[[True for j in range(W)] for i in range(H)] # 障害物がなければTrue
for i in range(H):
    S=input()
    for j in range(W):
        if S[j]=='#':
            g[i][j]=False
D=[[0 for j in range(W)] for i in range(H)]
U=[[0 for j in range(W)] for i in range(H)]
R=[[0 for j in range(W)] for i in range(H)]
L=[[0 for j in range(W)] for i in range(H)]

for i in range(H):
    for j in range(W):
        if j==0:
            L[i][j]=1 if g[i][j] else 0
        else:
            L[i][j]=L[i][j-1]+1 if g[i][j] else 0
    for j in reversed(range(W)):
        if j==W-1:
            R[i][j]=1 if g[i][j] else 0
        else:
            R[i][j]=R[i][j+1]+1 if g[i][j] else 0

for j in range(W):
    for i in range(H):
        if i==0:
            U[i][j]=1 if g[i][j] else 0
        else:
            U[i][j]=U[i-1][j]+1 if g[i][j] else 0
    for i in reversed(range(H)):
        if i==H-1:
            D[i][j]=1 if g[i][j] else 0
        else:
            D[i][j]=D[i+1][j]+1 if g[i][j] else 0

ans=0

for i in range(H):
    for j in range(W):
        if g[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:
def light(y,x):
    global g
    if not g[y][x]:
        return 0
    else:
        x0,y0=x,y
        L,R,U,D=0,0,0,0
        while x>=1 and g[y][x-1]:
            L+=1
            x-=1
        x,y=x0,y0
        while x<=W-2 and g[y][x+1]:
            R+=1
            x+=1
        x,y=x0,y0
        while y>=1 and g[y-1][x]:
            U+=1
            y-=1
        x,y=x0,y0
        while y<=H-2 and g[y+1][x]:
            D+=1
            y+=1
        return 1+L+R+U+D
        
H,W=map(int,input().split())
g=[[True for j in range(W)] for i in range(H)] # 障害物がなければTrue
for i in range(H):
    S=input()
    for j in range(W):
        if S[j]=='#':
            g[i][j]=False
D=[[0 for j in range(W)] for i in range(H)]
U=[[0 for j in range(W)] for i in range(H)]
R=[[0 for j in range(W)] for i in range(H)]
L=[[0 for j in range(W)] for i in range(H)]

for i in range(H):
    for j in range(W):
        if j==0:
            L[i][j]=1 if g[i][j] else 0
        else:
            L[i][j]=L[i][j-1]+1 if g[i][j] else 0
    for j in reversed(range(W)):
        if j==W-1:
            R[i][j]=1 if g[i][j] else 0
        else:
            R[i][j]=R[i][j+1]+1 if g[i][j] else 0

for j in range(W):
    for i in range(H):
        if i==0:
            U[i][j]=1 if g[i][j] else 0
        else:
            U[i][j]=U[i-1][j]+1 if g[i][j] else 0
    for i in reversed(range(H)):
        if i==H-1:
            D[i][j]=1 if g[i][j] else 0
        else:
            D[i][j]=D[i+1][j]+1 if g[i][j] else 0

ans=0

for i in range(H):
    for j in range(W):
        if g[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:
def light(y,x):
    global g
    if not g[y][x]:
        return 0
    else:
        x0,y0=x,y
        L,R,U,D=0,0,0,0
        while x>=1 and g[y][x-1]:
            L+=1
            x-=1
        x,y=x0,y0
        while x<=W-2 and g[y][x+1]:
            R+=1
            x+=1
        x,y=x0,y0
        while y>=1 and g[y-1][x]:
            U+=1
            y-=1
        x,y=x0,y0
        while y<=H-2 and g[y+1][x]:
            D+=1
            y+=1
        return 1+L+R+U+D
        
H,W=map(int,input().split())
g=[[True for j in range(W)] for i in range(H)] # 障害物がなければTrue
for i in range(H):
    S=input()
    for j in range(W):
        if S[j]=='#':
            g[i][j]=False

ans=0

for i in range(H):
    for j in range(W):
        if g[i][j]:
            ans=max(ans,light(i,j))
            
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

for j in range(W):
    if height[j] > 0:
        temp = width_max[j] + height[j] - 1
        if ans < temp:
            ans = temp
        height[j] = 0 

print(ans)

Submission status: Time Limit Exceeded

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

for j in range(W):
    if height[j] > 0:
        temp = width_max[j] + height[j] - 1
        if ans < temp:
            ans = temp
        height[j] = 0 

print(ans)

Submission status: Time Limit Exceeded

Solution code:
H,W = map(int,input().split())
S = []
height, ans = [0] * (W+1), 0
for i in range(H):
    s = list(input()) + [0]
    length = 0
    for j in range(W+1):
        if s[j] == '.':
            length += 1
            height[j] += 1
        else:
            s[j] = 0
            if length > 0:
                s = s[:(j-length)] + [length]*length + s[j:]
                length = 0
            if height[j] > 0:
                temp = max(S[i - k - 1][j] for k in range(height[j])) + height[j] - 1
                if ans < temp:
                    ans = temp
                height[j] = 0 
    S.append(s)

for j in range(W):
    if height[j] > 0:
        temp = max(S[i - k - 1][j] for k in range(height[j])) + height[j] - 1
        if ans < temp:
            ans = temp

print(ans)

Submission status: Time Limit Exceeded

Solution code:
H,W = map(int,input().split())
S = []
heigth = [0] * (W+1)
for i in range(H):
    s = list(input()) + [0]
    length = 0
    for j in range(W+1):
        if s[j] == '.':
            length += 1
            heigth[j] += 1
        else:
            s[j] = 0
            if length > 0:
                s = s[:(j-length)] + [length]*length + s[j:]
                length = 0
            if heigth[j] > 0:
                for k in range(heigth[j]):
                    S[i - k - 1][j] += heigth[j] - 1
                heigth[j] = 0 
    S.append(s)

for j in range(W):
    if heigth[j] > 0:
        for k in range(heigth[j]):
            S[i - k][j] += heigth[j] - 1

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

Submission status: Time Limit Exceeded

Solution code:
h, w = map(int, input().split())
s = ['#' * (w + 2)] + ['#' + input() + '#' for i in range(h)] + ['#' * (w + 2)]


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

for y in range(1, h + 1):
    for x in range(1, w + 1):
        if s[y][x]=='.':
            r[y][x] = r[y][x - 1] + 1
for y in range(1, h + 1):
    for x in range(w + 1, 0, -1):
        if s[y][x]=='.':
            l[y][x] = l[y][x + 1] + 1
for x in range(1, w + 1):
    for y in range(1, h + 1):
        if s[y][x]=='.':
            u[y][x] = u[y - 1][x] + 1

for x in range(1, w + 1):
    for y in range(h + 1, 0, -1):
        if s[y][x]=='.':
            d[y][x] = d[y + 1][x] + 1

# for x in range(w+2):
#     flag = 0
#     for y in range(h+2):
#         if s[y][x] == '#':
#             for yy in range(flag, y):
#                 tate[yy][x] = y - flag
#             flag = y + 1

# s = ['#' * (w + 2)] + ['#' + input() + '#' for i in range(h)] + ['#' * (w + 2)]
# yoko = [[0 for i in range(w+2)] for j in range(h+2)]
# tate = [[0 for i in range(w+2)] for j in range(h+2)]
# for y in range(h+2):
#     flag = 0
#     for x in range(w+2):
#         if s[y][x] == '#':
#             for xx in range(flag, x):
#                 yoko[y][xx] = x - flag
#             flag = x + 1
# for x in range(w+2):
#     flag = 0
#     for y in range(h+2):
#         if s[y][x] == '#':
#             for yy in range(flag, y):
#                 tate[yy][x] = y - flag
#             flag = y + 1

# [print(t) for t in r]
# print()
# [print(t) for t in l]
# print()
# [print(t) for t in u]
# print()
# [print(t) for t in d]



ans = -1
for y in range(h+2):
    for x in range(w+2):
        ans = max(ans, r[y][x] + l[y][x]+u[y][x]+d[y][x] - 3)
print(ans)