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())
field=[0]+["#"+input()+"#" for i in range(h)]+[0]
field[0],field[-1]="#"*(w+2),"#"*(w+2)
l,r,u,d=[[0 for i in range(w+2)] for i in range(h+2)],[[0 for i in range(w+2)] for i in range(h+2)],[[0 for i in range(w+2)] for i in range(h+2)],[[0 for i in range(w+2)] for i in range(h+2)]
for i in range(1,h+1):
  for j in range(1,w+1):
    if field[i][j]=="#":continue
    l[i][j]=l[i][j-1]+1
    u[i][j]=u[i-1][j]+1
for i in range(1,h+1)[::-1]:
  for j in range(1,w+1)[::-1]:
    if field[i][j]=="#":continue
    r[i][j]=r[i][j+1]+1
    d[i][j]=d[i+1][j]+1
ans=0
for i in range(h+2):
  for j in range(w+2):
    c=l[i][j]+r[i][j]+u[i][j]+d[i][j]-3
    if c>ans:ans=c
print(ans)

Submission status: Time Limit Exceeded

Solution code:
H, W = list(map(int, input().split()))
M = [[True for w in range(W)] for h in range(H)]
for h in range(0, H):
    Col = list(input())
    for w in range(0, W):
        if Col[w] == '#':
            M[h][w] = False
mx = 0
for h in range(0, H):
    for w in range(0, W):
        if not M[h][w]:
            continue
        c = 1
        for d in range(w - 1, -1, -1):
            if not M[h][d]:
                break
            c += 1
        for d in range(w + 1, W):
            if not M[h][d]:
                break
            c += 1
        for d in range(h - 1, -1, -1):
            if not M[d][w]:
                break
            c += 1
        for d in range(h + 1, H):
            if not M[d][w]:
                break
            c += 1
        if c > mx:
            mx = c
print(mx)

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python
# coding: utf-8

# In[27]:


import numpy as np
H, W = map(int, input().split())
S = np.array([list(input()) for i in range(H)])
"""
4 6
#..#..
.....#
....#.
#.#...
"""


# In[51]:


row_beam = np.zeros((H, W))
col_beam = np.zeros((H, W))
sh, sw = np.where(S=='#')


# In[52]:


#np.where()
for i in range(H):
    #print(i)
    #print(row_beam)
    row = S[i]
    #sharp_pos = np.where(row=='#')[0]
    sharp_pos = sw[sh==i]
    #print(sharp_pos)
    if len(sharp_pos) == 0:
        row_beam[i] = W
    else:
        s = 0
        for sp in sharp_pos:
            contin = sp-s
            row_beam[i, s:sp] = contin
            s = sp+1
        if s != W:
            row_beam[i, s:W] = W-s
            
for i in range(W):
    #print(i)
    #print(col_beam)
    col = S[:,i]
    #sharp_pos = np.where(col=='#')[0]
    sharp_pos = sh[sw==i]
    #print(sharp_pos)
    if len(sharp_pos) == 0:
        col_beam[:, i] = H
    else:
        s = 0
        for sp in sharp_pos:
            contin = sp-s
            col_beam[s:sp, i] = contin
            s = sp+1
        if s != W:
            col_beam[s:H, i] = H-s


# In[53]:


print(int(np.max(row_beam+col_beam-1)))


# In[54]:


#print(row_beam)
#print(col_beam)


# In[ ]:

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python
# coding: utf-8

# In[27]:


import numpy as np
H, W = map(int, input().split())
S = np.array([list(input()) for i in range(H)])
"""
4 6
#..#..
.....#
....#.
#.#...
"""


# In[47]:


row_beam = np.zeros((H, W))
col_beam = np.zeros((H, W))


# In[48]:


for i in range(H):
    #print(i)
    #print(row_beam)
    row = S[i]
    sharp_pos = np.where(row=='#')[0]
    #print(sharp_pos)
    if len(sharp_pos) == 0:
        row_beam[i] = W
    else:
        s = 0
        for sp in sharp_pos:
            contin = sp-s
            row_beam[i, s:sp] = contin
            s = sp+1
        if s != W:
            row_beam[i, s:W] = W-s
            
for i in range(W):
    #print(i)
    #print(col_beam)
    col = S[:,i]
    sharp_pos = np.where(col=='#')[0]
    #print(sharp_pos)
    if len(sharp_pos) == 0:
        col_beam[:, i] = H
    else:
        s = 0
        for sp in sharp_pos:
            contin = sp-s
            col_beam[s:sp, i] = contin
            s = sp+1
        if s != W:
            col_beam[s:H, i] = H-s


# In[49]:


print(int(np.max(row_beam+col_beam-1)))


# In[ ]:

Submission status: Time Limit Exceeded

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

L = [[None] * W for _ in range(H)]
R = [[None] * W for _ in range(H)]
D = [[None] * W for _ in range(H)]
U = [[None] * W for _ in range(H)]

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

ans = max([max([L[i][j] + R[i][j] + D[i][j] + U[i][j] - 3 for j in range(W)]) for i in range(H)])
print(ans)

Submission status: Time Limit Exceeded

Solution code:
class Counter:
  def __init__(self):
    self.v = 0

  def increment(self):
    self.v += 1


H, W = map(int, input().strip().split())

M = [None] * H
MX = [None] * H
MY = [None] * H

for i in range(H):
  M[i] = [c == '.' for c in input().strip()]
  MX[i] = [None] * W
  MY[i] = [None] * W

max_size = 0

for i in range(H):
  for j in range(W):
    if not M[i][j]: continue

    if MX[i][j] is None:
      tmp = Counter()
      for x in range(j, W):
        if not M[i][x]: break
        MX[i][x] = tmp
        tmp.increment()

    if MY[i][j] is None:
      tmp = Counter()
      for y in range(i, H):
        if not M[y][j]: break
        MY[y][j] = tmp
        tmp.increment()

    size = MX[i][j].v + MY[i][j].v - 1
    max_size = max(max_size, size)

print(max_size)

Submission status: Time Limit Exceeded

Solution code:
H, W = map(int, input().strip().split())

M = [None] * H
MX = [None] * H
MY = [None] * H

for i in range(H):
  M[i] = [c == '.' for c in input().strip()]
  MX[i] = [None] * W
  MY[i] = [None] * W

max_size = 0

for i in range(H):
  for j in range(W):
    if not M[i][j]: continue

    x_len = 0
    if MX[i][j] is None:
      for x in range(j, W):
        if not M[i][x]: break
        x_len += 1
      for x in range(j, j + x_len):
        MX[i][x] = x_len
    else:
      x_len = MX[i][j]

    y_len = 0
    if MY[i][j] is None:
      for y in range(i, H):
        if not M[y][j]: break
        y_len += 1
      for y in range(i, i + y_len):
        MY[y][j] = y_len
    else:
      y_len = MY[i][j]

    size = x_len + y_len - 1
    max_size = max(max_size, size)

print(max_size)

Submission status: Time Limit Exceeded

Solution code:
import copy
 
h, w = map(int, input().split())
s = [input() for _ in range(h)]
canlight = [[int(c == '.') for c in s[y]] for y in range(h)]
leftbeam = copy.deepcopy(canlight)
rightbeam = copy.deepcopy(canlight)
downbeam = copy.deepcopy(canlight)
upbeam = copy.deepcopy(canlight)
 
for y in range(h):
    for x in range(w - 1):
        leftbeam[y][x + 1] = (leftbeam[y][x] + 1) * canlight[y][x + 1]
    for x in range(1, w):
        rightbeam[y][-(x + 1)] = (rightbeam[y][-x] + 1) * canlight[y][-(x + 1)]
 
for x in range(w):
    for y in range(h - 1):
        downbeam[y + 1][x] = (downbeam[y][x] + 1) * canlight[y + 1][x]
    for y in range(1, h):
        upbeam[-(y + 1)][x] = (upbeam[-y][x] + 1) * canlight[-(y + 1)][x]
 
ans = 0
for y in range(h):
    for x in range(w):
        ans = max(ans, leftbeam[y][x] + rightbeam[y][x]
                     + downbeam[y][x] + upbeam[y][x] - 3)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import copy

h, w = map(int, input().split())
s = [input() for _ in range(h)]
canlight = [[int(c == '.') for c in s[y]] for y in range(h)]
leftbeam = copy.deepcopy(canlight)
rightbeam = copy.deepcopy(canlight)
downbeam = copy.deepcopy(canlight)
upbeam = copy.deepcopy(canlight)

for y in range(h):
    for x in range(w - 1):
        leftbeam[y][x + 1] = (leftbeam[y][x] + 1) * canlight[y][x + 1]
        rightbeam[y][-(x + 2)] = (rightbeam[y][-(x + 1)] + 1) * canlight[y][-(x + 2)]

for x in range(w):
    for y in range(h - 1):
        downbeam[y + 1][x] = (downbeam[y][x] + 1) * canlight[y + 1][x]
        upbeam[-(y + 2)][x] = (upbeam[-(y + 1)][x] + 1) * canlight[-(y + 2)][x]

ans = 0
for y in range(h):
    for x in range(w):
        ans = max(ans, leftbeam[y][x] + rightbeam[y][x]
                     + downbeam[y][x] + upbeam[y][x] - 3)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import copy

h, w = map(int, input().split())
s = [input() for _ in range(h)]
canlight = [[int(c == '.') for c in s[y]] for y in range(h)]
leftbeam = copy.deepcopy(canlight)
rightbeam = copy.deepcopy(canlight)
downbeam = copy.deepcopy(canlight)
upbeam = copy.deepcopy(canlight)

for y in range(h):
    for x in range(w - 1):
        leftbeam[y][x + 1] = (leftbeam[y][x] + 1) * canlight[y][x + 1]
    for x in range(1, w):
        rightbeam[y][-(x + 1)] = (rightbeam[y][-x] + 1) * canlight[y][-(x + 1)]

for x in range(w):
    for y in range(h - 1):
        downbeam[y + 1][x] = (downbeam[y][x] + 1) * canlight[y + 1][x]
    for y in range(1, h):
        upbeam[-(y + 1)][x] = (upbeam[-y][x] + 1) * canlight[-(y + 1)][x]

ans = 0
for y in range(h):
    for x in range(w):
        ans = max(ans, leftbeam[y][x] + rightbeam[y][x]
                     + downbeam[y][x] + upbeam[y][x] - 3)
print(ans)

Submission status: Time Limit Exceeded

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

def can_light(y, x):
    return (0 <= y < h) and (0 <= x < w) and s[y][x] == '.'

for y in range(h):
    beamlen = 0
    for x in range(w):
        if can_light(y, x):
            beamlen += 1
        else:
            beamlen = 0
        leftbeam[y][x] = beamlen

for y in range(h):
    beamlen = 0
    for x in range(w):
        if can_light(y, w - x - 1):
            beamlen += 1
        else:
            beamlen = 0
        rightbeam[y][w - x - 1] = beamlen


for x in range(w):
    beamlen = 0
    for y in range(h):
        if can_light(y, x):
            beamlen += 1
        else:
            beamlen = 0
        downbeam[y][x] = beamlen

for x in range(w):
    beamlen = 0
    for y in range(h):
        if can_light(h - y - 1, x):
            beamlen += 1
        else:
            beamlen = 0
        upbeam[h - y - 1][x] = beamlen

ans = 0
for y in range(h):
    for x in range(w):
        ans = max(ans, leftbeam[y][x] + rightbeam[y][x]
                     + downbeam[y][x] + upbeam[y][x] - 3)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
def main():
    h,w = map(int,input().split())
    a = {}
    for i in range(h):
        a[i] = input()
    ans = 0
    L = []
    R = []
    D = []
    U = []
    for x in range(h):
        L.append([])
        R.append([])
        for y in range(w):
            if a[x][y] == "#":
                L[x].append(0)
            elif y == 0:
                L[x].append(1)
            else:
                L[x].append(L[x][y-1]+1)
        for y in range(w-1,-1,-1):
            if a[x][y] == "#":
                R[x].append(0)
            elif y == w-1:
                R[x].append(1)
            else:
                R[x].append(R[x][w-y-2]+1)
        R[x].reverse()
    for y in range(w):
        D.append([])
        U.append([])
        for x in range(h):
            if a[x][y] == "#":
                U[y].append(0)
            elif x == 0:
                U[y].append(1)
            else:
                U[y].append(U[y][x-1]+1)
        for x in range(h-1,-1,-1):
            if a[x][y] == "#":
                D[y].append(0)
            elif x == h-1:
                D[y].append(1)
            else:
                D[y].append(D[y][h-x-2]+1)
        D[y].reverse()

    for x in range(h):
        for y in range(w):
            ans = max(ans, R[x][y]+L[x][y]+U[y][x]+D[y][x]-3)
            
    print(ans)
main()

Submission status: Time Limit Exceeded

Solution code:
def main():
    h,w = map(int,input().split())
    a = {}
    for i in range(h):
        a[i] = input()
    ans = 0
    L = []
    R = []
    D = []
    U = []
    for x in range(h):
        L.append([])
        R.append([])
        for y in range(w):
            if a[x][y] == "#":
                L[x].append(0)
            elif y == 0:
                L[x].append(1)
            else:
                L[x].append(L[x][y-1]+1)
        for y in range(w-1,-1,-1):
            if a[x][y] == "#":
                R[x].append(0)
            elif y == w-1:
                R[x].append(1)
            else:
                R[x].append(R[x][w-y-2]+1)
        R[x].reverse()
    for y in range(w):
        D.append([])
        U.append([])
        for x in range(h):
            if a[x][y] == "#":
                U[y].append(0)
            elif x == 0:
                U[y].append(1)
            else:
                U[y].append(U[y][x-1]+1)
        for x in range(h-1,-1,-1):
            if a[x][y] == "#":
                D[y].append(0)
            elif x == h-1:
                D[y].append(1)
            else:
                D[y].append(D[y][h-x-2]+1)
        D[y].reverse()

    for x in range(h):
        for y in range(w):
            ans = max(ans, R[x][y]+L[x][y]+U[y][x]+D[y][x]-3)
            
    print(ans)
main()

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
h,w = map(int,input().split())
s = [[j for j in input()] for i in range(h)]
d_2y = [[0] * w for i in range(h)]
d_2t = [[0] * w for i in range(h)]
d_2w = [[0] * w for i in range(h)]
for i in range(h):
  c = 0
  for j in range(w):
    if s[i][j] == '#':
      c = 0
    else:
      c += 1
    d_2y[i][j] = c
for i in range(h):
  for j in range(w-2,-1,-1):
    if s[i][j] == '#':
      continue
    else:
      d_2y[i][j] = max(d_2y[i][j+1],d_2y[i][j])
for i in range(w):
  c = 0
  for j in range(h):
    if s[j][i] == '#':
      c = 0
    else:
      c += 1
    d_2t[j][i] = c
for i in range(w):
  for j in range(h-2,-1,-1):
    if s[j][i] == '#':
      d_2t[j][i] = 0
    else:
      d_2t[j][i] = max(d_2t[j][i],d_2t[j+1][i])
m = 0
for i in range(h):
  for j in range(w):
    d_2w[i][j] = d_2y[i][j] + d_2t[i][j]
  m = max(m,max(d_2w[i]))
print(m-1)

Submission status: Time Limit Exceeded

Solution code:
def main():
    h,w = map(int,input().split())
    a = {}
    for i in range(h):
        a[i] = input()
    ans = 0
    def brighten(x,y):
        bright = 0
        up = x
        down = x
        right = y
        left = y
        while a[up][y] == ".":
            bright += 1
            if up == 0:
                break
            up -= 1
        while a[down][y] == ".":
            bright += 1
            if down == h-1:
                break
            down += 1
        while a[x][right] == ".":
            bright += 1
            if right == w-1:
                break
            right += 1
        while a[x][left] == ".":
            bright += 1
            if left == 0:
                break
            left -= 1
        bright -= 3
        return bright
    print
    for x in range(h):
        for y in range(w):
            if brighten(x,y) > ans:
                ans = brighten(x,y)
    print(ans)
main()

Submission status: Time Limit Exceeded

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

lrdu = [[[0 for i in range(W)] for j in range(H)] for k in range(4)]

for di in range(4):
    for i in range(H):
        if di == 2: i = H-1-i
        for j in range(W):
            if di == 1: j = W-1-j
            if S[i][j] == '#': lrdu[di][i][j] = 0
            else:
                if di == 0:
                    if j == 0: lrdu[di][i][j] = 1
                    elif j > 0: lrdu[di][i][j] = lrdu[di][i][j-1] + 1
                if di == 1:
                    if j == W-1: lrdu[di][i][j] = 1
                    elif j < W-1: lrdu[di][i][j] = lrdu[di][i][j+1] + 1
                if di == 2:
                    if i == H-1: lrdu[di][i][j] = 1
                    elif i < H-1: lrdu[di][i][j] = lrdu[di][i+1][j] + 1
                if di == 3:
                    if i == 0: lrdu[di][i][j] = 1
                    elif i > 0: lrdu[di][i][j] = lrdu[di][i-1][j] + 1

ans = 0
for i in range(H):
    for j in range(W):
        t = 0
        for k in range(4):
            t += lrdu[k][i][j]
        t -= 3
        if t > ans: ans = t
print(ans)

Submission status: Time Limit Exceeded

Solution code:
H, W = [int(_) for _ in input().split(" ")]
ret = []
for i in range(H):
    dummy = []
    for j in input():
        dummy += [[j, 0, 0, 0]]
    ret += [dummy]

_max = 0
for h in range(H):
    for w in range(W):
        if ret[h][w][0] == "#":
            continue
        if ret[h][w-1][0] == "#" or w-1 < 0:
            for w2 in range(w, W):
                if ret[h][w2][0] == "#":
                    ret[h][w][2] = w2 - w
                    break
                else:
                    ret[h][w][2] = w2 - w + 1
        else:
            ret[h][w][2] = ret[h][w-1][2]          

        if ret[h-1][w][0] == "#" or h-1 < 0:
            for h2 in range(h, H):
                if ret[h2][w][0] == "#":
                    ret[h][w][1] = h2 - h
                    break
                else:
                    ret[h][w][1] = h2 - h + 1
        else:
            ret[h][w][1] = ret[h-1][w][1]            
        
        if _max < ret[h][w][1] + ret[h][w][2] - 1:
          _max = ret[h][w][1] + ret[h][w][2] - 1

"""
for h in range(H):
	m = ""
	for w in range(W):
		if ret[h][w][0] == "#":
 			m += "%3s" %("#")
		else:
			m += "%3d" %(ret[h][w][3])
	print (m)

print (ret[0])
"""

print (_max)

Submission status: Time Limit Exceeded

Solution code:
H, W = map(int, input().split())
maze = [input() for i in range(H)]
dp_holi = [[0] * W for i in range(H)]
dp_ver = [[0] * W for i in range(H)]


#まずは水平方向について数える
for i in range(H):
    for j in range(W):
        if maze[i][j] == ".":
            if j - 1 < 0 or maze[i][j -1] == "#":
                tmp = 0
                flag = False
                for k in maze[i][j:]:
                    if k == ".":
                        tmp += 1
                        flag = True
                    else:
                        dp_holi[i][j] = tmp
                        break
                if flag:
                    dp_holi[i][j] = tmp
            elif maze[i][j - 1] == ".":
                dp_holi[i][j] += dp_holi[i][j - 1]

#垂直方向にも同じことをする
for i in range(H):
    for j in range(W):
        if maze[i][j] == ".":
            if i - 1 < 0 or maze[i -1][j] == "#":
                tmp = 0
                flag = False
                for k in range(i, H):
                    if maze[k][j] == ".":
                        tmp += 1
                        flag = True
                    else:
                        dp_ver[i][j] += tmp
                        flag = False
                        break
                if flag:
                    dp_ver[i][j] += tmp
            elif i - 1 < 0:
                continue
            elif maze[i - 1][j] == ".":
                dp_ver[i][j] += dp_ver[i - 1][j]

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

Submission status: Time Limit Exceeded

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

DPL = [[0 for _ in range(W+2)] for _ in range(H+2)]
DPR = [[0 for _ in range(W+2)] for _ in range(H+2)]
DPU = [[0 for _ in range(W+2)] for _ in range(H+2)]
DPD = [[0 for _ in range(W+2)] for _ in range(H+2)]

for h in range(1, H+1):
    for w in range(1, W+1):
        if Field[h][w] == '#':
            DPL[h][w] = 0
        else:
            DPL[h][w] = DPL[h][w-1] + 1
for h in range(1, H+1):
    for w in range(1, W+1):
        if Field[h][W-w+1] == '#':
            DPR[h][W-w+1] = 0
        else:
            DPR[h][W-w+1] = DPR[h][W-w+1+1] + 1
for h in range(1, H+1):
    for w in range(1, W+1):
        if Field[h][w] == '#':
            DPU[h][w] = 0
        else:
            DPU[h][w] = DPU[h-1][w] + 1   
for h in range(1, H+1):
    for w in range(1, W+1):
        if Field[H-h+1][w] == '#':
            DPD[H-h+1][w] = 0
        else:
            DPD[H-h+1][w] = DPD[H-h+1+1][w] + 1 
ans = 0          
for h in range(1, H+1):
    for w in range(1, W+1):
        ans = max(ans,DPL[h][w]+DPR[h][w]+DPU[h][w]+DPD[h][w])
print(ans-3)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
H,W = map(int,input().split())

field = [[0 for i in range(W)] for j in range(H)]
for i in range(H):
    field[i] = str(input());

L = [[0 for i in range(W)] for j in range(H)]

for i in range(H):
    for j in range(W):
        if field[i][j] == ".":
            ii = i
            jj = j
            while (ii < H and field[ii][jj] == "."):
                L[i][j] += 1
                ii += 1
            ii = i
            jj = j
            while (ii >= 0 and field[ii][jj] == "."):
                L[i][j] += 1
                ii -= 1
            ii = i
            jj = j
            while (jj < W and field[ii][jj] == "."):
                L[i][j] += 1
                jj += 1
            ii = i
            jj = j
            while (jj >= 0 and field[ii][jj] == "."):
                L[i][j] += 1
                jj -= 1

L = np.array(L)
ans = L
ans = L.max()
#ans = L[idx]
#ans = max(ans)
#ans = ans-3

print(ans-3)

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
#ABC129 D

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

for i in range(H):
    for j in range(W):
        if L[i][j] == '#':
            field[i][j] = False

A = []

for i in range(H):
    for j in range(W):
        if field[i][j]:
            ans = 1
            for k in range(1,H):
                if i + k < H:
                    if field[i+k][j]:
                        ans += 1
                    else:
                        break
                else:
                    break
            for k in range(1,H):
                if i - k >= 0:
                    if field[i-k][j]:
                        ans += 1
                    else:
                        break
                else:
                    break
            for k in range(1,W):
                if j + k < W:
                    if field[i][j+k]:
                        ans += 1
                    else:
                        break
                else:
                    break
            for k in range(1,W):
                if j - k >= 0:
                    if field[i][j-k]:
                        ans += 1
                    else:
                        break
                else:
                    break
            A.append(ans)
print(max(A))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

H, W = map(int, input().split())
S = np.array([list(input()) for _ in range(H)]) == '.'
T=np.zeros((H,W))
B=np.zeros((H,W))
L=np.zeros((H,W))
R=np.zeros((H,W))

for j in range(W):
    nt=0
    for i in range(1,H):  
        if S[i-1,j]:
            nt+=1          
        else:
            nt=0
        T[i,j]=nt

for j in range(W):
    nt=0
    for i in reversed(range(H-1)):
        if S[i+1,j]:
            nt+=1          
        else:
            nt=0
        B[i,j]=nt

for i in range(H):
    nt=0
    for j in range(1,W):
        if S[i,j-1]:
            nt+=1          
        else:
            nt=0
        L[i,j]=nt

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

na=0
for i in range(H):
    for j in range(W):
        if S[i,j]:
            nat=int(T[i,j]+B[i,j]+L[i,j]+R[i,j]+1)
            na=max(nat,na)

print(na)
#print(T)

Submission status: Time Limit Exceeded

Solution code:
import numpy
h,w=map(int,input().split())
s=[list(input())for _ in range(h)]
score=numpy.zeros((h,w))
ans=0
range_w=range(w)
range_h=range(h)
for i in range_h:
  tmp_1=0
  tmp_2=0
  for j in range_w:
    if s[i][j]=="#":
      tmp_1=0
    else:
      tmp_1+=1
    score[i][j]+=tmp_1
    
    if s[i][-j-1]=="#":
      tmp_2=0
    else:
      tmp_2+=1
    score[i][-j-1]+=tmp_2
    
for j in range_w:
  tmp_3=0
  tmp_4=0
  for i in range_h:
    if s[i][j]=="#":
      tmp_3=0
    else:
      tmp_3+=1
    score[i][j]+=tmp_3
    
    if s[-i-1][j]=="#":
      tmp_4=0
    else:
      tmp_4+=1
    score[-i-1][j]+=tmp_4-3
print(int(score.max()))

Submission status: Time Limit Exceeded

Solution code:
import numpy
h,w=map(int,input().split())
s=[list(input())for _ in range(h)]
score=numpy.zeros((h,w))
ans=0
range_w=range(w)
range_h=range(h)
r_range_w=range(w)[::-1]
r_range_h=range(h)[::-1]
for i in range_h:
  tmp=0
  for j in range_w:
    if s[i][j]=="#":
      tmp=0
    else:
      tmp+=1
    score[i][j]+=tmp
for i in range_h:
  tmp=0
  for j in r_range_w:
    if s[i][j]=="#":
      tmp=0
    else:
      tmp+=1
    score[i][j]+=tmp
for j in range_w:
  tmp=0
  for i in range_h:
    if s[i][j]=="#":
      tmp=0
    else:
      tmp+=1
    score[i][j]+=tmp
for j in range_w:
  tmp=0
  for i in r_range_h:
    if s[i][j]=="#":
      tmp=0
    else:
      tmp+=1
    score[i][j]+=tmp-3
    ans=max(ans,score[i][j])
# print(score)
print(int(ans))

Submission status: Time Limit Exceeded

Solution code:
h,w=map(int,input().split())
s=[list(input())for _ in range(h)]
score=[[0]*w for _ in range(h)]
ans=0
range_w=range(w)
range_h=range(h)
r_range_w=range(w)[::-1]
r_range_h=range(h)[::-1]
for i in range_h:
  tmp=0
  for j in range_w:
    if s[i][j]=="#":
      tmp=0
    else:
      tmp+=1
    score[i][j]+=tmp
for i in range_h:
  tmp=0
  for j in r_range_w:
    if s[i][j]=="#":
      tmp=0
    else:
      tmp+=1
    score[i][j]+=tmp
for j in range_w:
  tmp=0
  for i in range_h:
    if s[i][j]=="#":
      tmp=0
    else:
      tmp+=1
    score[i][j]+=tmp
for j in range_w:
  tmp=0
  for i in r_range_h:
    if s[i][j]=="#":
      tmp=0
    else:
      tmp+=1
    score[i][j]+=tmp-3
    ans=max(ans,score[i][j])
# print(score)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

H, W = map(int, input().split())
S = np.array([list(input()) for _ in range(H)]) == '.'
na=0
for i in range(H):
    for j in range(W):
        if S[i,j]:
            nat=1
            for ibw in reversed(range(i)):
                if S[ibw,j]:
                    nat+=1
                else:
                    break
            for ifw in range(i+1,H):
                if S[ifw,j]:
                    nat+=1
                else:
                    break
            for jbw in reversed(range(j)):
                if S[i,jbw]:
                    nat+=1
                else:
                    break
            for jfw in range(j+1,W):
                if S[i,jfw]:
                    nat+=1
                else:
                    break
            na=max(nat,na)

print(na)

Submission status: Time Limit Exceeded

Solution code:
import numpy
h,w=map(int,input().split())
s=[list(input())for _ in range(h)]
score=[[0]*w for _ in range(h)]
ans=0
for i in range(h):
  tmp=0
  for j in range(w):
    if s[i][j]=="#":
      tmp=0
    else:
      tmp+=1
    score[i][j]+=tmp
for i in range(h):
  tmp=0
  for j in reversed(range(w)):
    if s[i][j]=="#":
      tmp=0
    else:
      tmp+=1
    score[i][j]+=tmp
for j in range(w):
  tmp=0
  for i in range(h):
    if s[i][j]=="#":
      tmp=0
    else:
      tmp+=1
    score[i][j]+=tmp
for j in range(w):
  tmp=0
  for i in reversed(range(h)):
    if s[i][j]=="#":
      tmp=0
    else:
      tmp+=1
    score[i][j]+=tmp-3
    ans=max(ans,score[i][j])
# print(score)
print(ans)

Submission status: Time Limit Exceeded

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

N, M, = map(int, input().split())
MAP = [list(input().strip()) for _ in range(N)]
ANS = [None] * N

for i in range(N):
    ANS[i] = [[0, 0] for _ in range(M)]

for i in range(N):
    for j in range(M):
        t = MAP[i][j]
        
        if t == ".":
            if j != 0:
                ANS[i][j][0] += 1 + ANS[i][j - 1][0]
            else:
                ANS[i][j][0] = 1

    for j in reversed(range(M)):
        t = ANS[i][j][0]
        
        if t > 1:
            if j != 0 and ANS[i][j - 1][0] != 0:
                ANS[i][j - 1][0] = ANS[i][j][0]
                
for j in range(M):
    for i in range(N):
        t = MAP[i][j]
        
        if t == ".":
            if i != 0:
                ANS[i][j][1] += 1 + ANS[i - 1][j][1]
            else:
                ANS[i][j][1] = 1
                
    for i in reversed(range(N)):
        t = ANS[i][j][1]
        
        if t > 1:
            if i != 0 and ANS[i - 1][j][1] != 0:
                ANS[i - 1][j][1] = ANS[i][j][1]

ans = 0
for i in range(N):
    for j in range(M):
        ans = max(ans, sum(ANS[i][j]) - 1)
        
print(ans)