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=[]
for i in range(h):
    s.append(list(input()) )

l=[[0]*w for _ in range(h)]
for i in range(h):
    count=0
    for j in range(w):
        if s[i][j] ==".":
            count+=1
        else:
            count=0
        l[i][j]=count
        
r=[[0]*w for _ in range(h)]
for i in range(h-1,-1,-1):
    count=0
    for j in range(w-1,-1,-1):
        if s[i][j] ==".":
            count+=1
        else:
            count=0
        r[i][j]=count
                
d=[[0]*w for _ in range(h)]
for j in range(w-1,-1,-1):
    count=0
    for i in range(h-1,-1,-1):
        if s[i][j] ==".":
            count+=1
        else:
            count=0
        d[i][j]=count
                
u=[[0]*w for _ in range(h)]
for j in range(w):
    count=0
    for i in range(h):
        if s[i][j] ==".":
            count+=1
        else:
            count=0
        u[i][j]=count

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

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

h,w = map(int, input().split())
s = (np.array([input() for _ in range(h)]))
ans = [list() for i in range(h)]
for key_i,i in enumerate(s):
  m = 0
  for j in i:
    if j == ".":
      m += 1
    else:
      for k in range(m):
        ans[key_i].append(m)
      m = 0
      ans[key_i].append(m)
  for k in range(m):
    ans[key_i].append(m)

ans = np.array(ans)
ans = ans.T
ans2 = [list() for i in range(w)]
for key_i,i in enumerate(ans):
  m = 0
  for j in i:
    if j:
      m += 1
    else:
      for k in range(m):
        ans2[key_i].append(m)
      m = 0
      ans2[key_i].append(m)
  for k in range(m):
    ans2[key_i].append(m)
ans2 = np.array(ans2)
print(np.max(ans + ans2) - 1)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

h,w = map(int, input().split())
s = (np.array([input() for _ in range(h)]))
ans = [list() for i in range(h)]
for key_i,i in enumerate(s):
  m = 0
  for j in i:
    if j == ".":
      m += 1
    else:
      for k in range(m):
        ans[key_i].append(m)
      m = 0
      ans[key_i].append(m)
  for k in range(m):
    ans[key_i].append(m)

ans = np.array(ans)
ans = ans.T
ans2 = [list() for i in range(w)]
for key_i,i in enumerate(ans):
  m = 0
  for j in i:
    if j:
      m += 1
    else:
      for k in range(m):
        ans2[key_i].append(m)
      m = 0
      ans2[key_i].append(m)
  for k in range(m):
    ans2[key_i].append(m)
print(np.max(ans + ans2) - 1)

Submission status: Time Limit Exceeded

Solution code:
from collections import deque
H, W = map(int, input().split())
rows = [input() for i in range(H)]
cols = []
for i in range(W):
    col = ''
    for row in rows:
        col += row[i]
    cols.append(col)

def create_light_list(tdl, reverse):
    ret = []
    lenl = len(tdl[0])
    tl = range(lenl)[::-1] if reverse else range(lenl)
    for l in tdl:
        d = deque()
        cur = 0
        for i in tl:
            if l[i] == '#':
                cur = 0
            else:
                cur += 1
            if reverse:
                d.appendleft(cur)
            else:
                d.append(cur)
        ret.append(d)
    return ret

# 上下左右の照らされる数だけをあらかじめ計算
L = create_light_list(rows, False)
R = create_light_list(rows, True)
U = create_light_list(cols, False)
D = create_light_list(cols, True)

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
H, W = map(int, input().split())
rows = [input() for i in range(H)]
cols = []
for i in range(W):
    col = ''
    for row in rows:
        col += row[i]
    cols.append(col)

def create_light_list(tdl, reverse):
    ret = []
    for l in tdl:
        lenl = len(l)
        items = []
        cur = 0
        if reverse:
            tl = range(lenl)[::-1]
        else:
            tl = range(lenl)
        for i in tl:
            if l[i] == '#':
                cur = 0
                items.append(cur)
            else:
                cur += 1
                items.append(cur)
        if reverse:
            ret.append(items[::-1])
        else:
            ret.append(items)
    return ret

# 上下左右の照らされる数だけをあらかじめ計算
L = create_light_list(rows, False)
R = create_light_list(rows, True)
U = create_light_list(cols, False)
D = create_light_list(cols, True)

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

print(ans)

Submission status: Time Limit Exceeded

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

grid2 = [[0]*W for i in range(H)]
grid3 = [[0]*W for i in range(H)]
for i in range(H):
    for j in range(W):
        if grid[i][j] == "#":
            grid2[i][j] = 0
        else:
            if j > 0:
                grid2[i][j] = grid2[i][j-1]+1
            else:
                grid2[i][j] = 1
    for j in reversed(range(W)):
        if grid2[i][j] != 0 and j != W-1:
            grid2[i][j] = max(grid2[i][j], grid2[i][j+1])

for j in range(W):
    for i in range(H):
        if grid[i][j] == "#":
            grid3[i][j] = 0
        else:
            if i > 0:
                grid3[i][j] = grid3[i-1][j]+1
            else:
                grid3[i][j] = 1
    for i in reversed(range(H)):
        if grid3[i][j] != 0 and i != H-1:
            grid3[i][j] = max(grid3[i][j], grid3[i+1][j])
ans = 0
for i in range(H):
    for j in range(W):
        ans = max(ans, grid2[i][j] + grid3[i][j] - 1)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
H,W = map(int,input().split())
S=[]
for i in range(H):
    S+=[str(input())]
T=np.zeros((H+2,W+2),np.int32)
for i in range(H):
    for j in range(W):
        if S[i][j]=='.':
            T[i+1][j+1]=1
        elif S[i][j]=='#':
            T[i+1][j+1]=0

X=np.zeros((H+2,W+2),np.int32)
 
for i in range(H+2):
    p=0
    for j in range(W+2):
        if T[i][j]==0:
            p=j
        else:
            X[i][j]-=p
 
for i in range(H+2):
    p=0
    for j in range(W+2):
        if T[i][W+1-j]==0:
            p=W+1-j
        else:
            X[i][W+1-j]+=p
            
 
 
for j in range(W+2):
    p=0
    for i in range(H+2):
        if T[i][j]==0:
            p=i
        else:
            X[i][j]-=p
            
for j in range(W+2):
    p=0
    for i in range(H+2):
        if T[H+1-i][j]==0:
            p=H+1-i
        else:
            X[H+1-i][j]+=p
            
answer=np.max(X)-3
print(answer)

Submission status: Time Limit Exceeded

Solution code:
H, W = map(int, input().split())
S = []
for i in range(H):
  S.append(list(str(input())))
import numpy as np
S = np.array(S)

left = np.zeros((H, W))
right = np.zeros((H, W))
up = np.zeros((H, W))
down = np.zeros((H, W))

for i in range(H):
  point = 0
  for j in range(W):
    if S[i, j] == ".":
      point += 1
      left[i, j] = point
    elif S[i, j] == "#":
      point = 0

for i in range(H):
  point = 0
  for j in range(W-1, -1, -1):
    if S[i, j] == ".":
      point += 1
      right[i,j] = point
    elif S[i, j] == "#":
      point = 0
    
for i in range(W):
  point = 0
  for j in range(H):
    if S[j, i] == ".":
      point += 1
      up[j, i] = point
    elif S[j, i] == "#":
      point = 0
      
for i in range(W):
  point = 0
  for j in range(H-1, -1, -1):
    if S[j, i] == ".":
      point += 1
      down[j, i] = point
    elif S[j, i] == "#":
      point = 0
score = right + left + up + down
print(int(np.max(score)-3))

Submission status: Time Limit Exceeded

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

def solve(i,j):
	if S[i][j] == "#":
		return 0
	cnt = 1
	tmp = j
	while True:
		tmp -= 1
		if tmp < 0:
			break
		if S[i][tmp] == "#":
			break
		cnt += 1
	tmp = j
	while True:
		tmp += 1
		if tmp >= W:
			break
		if S[i][tmp] == "#":
			break
		cnt += 1
	tmp = i
	while True:
		tmp -= 1
		if tmp < 0:
			break
		if S[tmp][j] == "#":
			break
		cnt += 1
	tmp = i
	while True:
		tmp += 1
		if tmp >= H:
			break
		if S[tmp][j] == "#":
			break
		cnt += 1

	return cnt
		
ans = 0
for i in range(H):
	for j in range(W):
		ans = max(ans, solve(i,j))

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
H,W = map(int,input().split())
S=[]
for i in range(H):
    S+=[str(input())]
T=np.array([[0]*(W+2)]*(H+2))
for i in range(H):
    for j in range(W):
        if S[i][j]=='.':
            T[i+1][j+1]=1
        elif S[i][j]=='#':
            T[i+1][j+1]=0

X=np.array([[0]*(W+2)]*(H+2))

for i in range(H+2):
    p=0
    for j in range(W+2):
        if T[i][j]==0:
            p=j
        else:
            X[i][j]-=p

for i in range(H+2):
    p=0
    for j in range(W+2):
        if T[i][W+1-j]==0:
            p=W+1-j
        else:
            X[i][W+1-j]+=p
            


for j in range(W+2):
    p=0
    for i in range(H+2):
        if T[i][j]==0:
            p=i
        else:
            X[i][j]-=p
            
for j in range(W+2):
    p=0
    for i in range(H+2):
        if T[H+1-i][j]==0:
            p=H+1-i
        else:
            X[H+1-i][j]+=p
            
answer=np.max(X)-3
print(answer)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
H,W = map(int,input().split())
S=[]
for i in range(H):
    S+=[str(input())]
T=np.array([[0]*(W+2)]*(H+2))
for i in range(H):
    for j in range(W):
        if S[i][j]=='.':
            T[i+1][j+1]=1
        elif S[i][j]=='#':
            T[i+1][j+1]=0

X_L=np.array([[0]*(W+2)]*(H+2))
X_R=np.array([[0]*(W+2)]*(H+2))

for i in range(H+2):
    p=0
    for j in range(W+2):
        if T[i][j]==0:
            p=j
        else:
            X_L[i][j]=p

for i in range(H+2):
    p=0
    for j in range(W+2):
        if T[i][W+1-j]==0:
            p=W+1-j
        else:
            X_R[i][W+1-j]=p
            
X_U=np.array([[0]*(W+2)]*(H+2))
X_D=np.array([[0]*(W+2)]*(H+2))

for j in range(W+2):
    p=0
    for i in range(H+2):
        if T[i][j]==0:
            p=i
        else:
            X_U[i][j]=p
            
for j in range(W+2):
    p=0
    for i in range(H+2):
        if T[H+1-i][j]==0:
            p=H+1-i
        else:
            X_D[H+1-i][j]=p
            
answer=np.amax(X_D-X_U+X_R-X_L)-3
print(answer)