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=input()
  s.append(S)
L=[[0 for i in range(w)] for j in range(h)]
R=[[0 for i in range(w)] for j in range(h)]
U=[[0 for i in range(w)] for j in range(h)]
D=[[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]=='.':
      if i==0:
        L[i][j]=1
      else:
        L[i][j]=L[i-1][j]+1
    else:
      L[i][j]=0
    
    if s[h-1-i][j]=='.':
      if i==0:
        R[h-1-i][j]=1
      else:
        R[h-1-i][j]=R[h-i][j]+1
    else:
      R[h-1-i][j]=0
      
for j in range(w):
  for i in range(h):
    if s[i][j]=='.':
      if j==0:
        U[i][j]=1
      else:
        U[i][j]=U[i][j-1]+1
    else:
      U[i][j]=0
    
    if s[i][w-1-j]=='.':
      if j==0:
        D[i][w-1-j]=1
      else:
        D[i][w-1-j]=D[i][w-j]+1
    else:
      D[i][w-1-j]=0
      
ans=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)

Submission status: Time Limit Exceeded

Solution code:
H, W = map(int,input().split())
S = [ str(input()) for i in range(H) ]
sumlist = []
for i in range(H):
    tmp = 0
    for j in range(W):
        if S[i][j] == '#':
            for k in range(tmp):
                sumlist.append(tmp)
            sumlist.append(0)
            tmp = 0
            continue
        else:
            tmp += 1
    for k in range(tmp):
        sumlist.append(tmp)
sumlist2 = []
for i in range(W):
    tmp = 0
    for j in range(H):
        if S[j][i] == '#':
            for k in range(tmp):
                sumlist2.append(tmp)
            sumlist2.append(0)
            tmp = 0
            continue
        else:
            tmp += 1
    for k in range(tmp):
        sumlist2.append(tmp)
res = [sumlist[i]+sumlist2[(i%W)*H+(i//W)] for i in range(H*W)]
print(max(res)-1)

Submission status: Time Limit Exceeded

Solution code:
h, w = map(int, input().split())
S = [list(input()) for _ in range(h)]
L = [[0] * w for _ in range(h)]
for i in range(h):
    for j in range(w):
        # if S[i][j] == '#':
        #     L[i][j] = 0
        if S[i][j] == '.':
            if j == 0:
                L[i][j] = 1
            else:
                L[i][j] = L[i][j-1] + 1
R = [[0] * w for _ in range(h)]
for i in range(h):
    for j in reversed(range(w)):
        # if S[i][j] == '#':
        #     R[i][j] = 0
        if S[i][j] == '.':
            if j == w-1:
                R[i][j] = 1
            else:
                R[i][j] = R[i][j+1] + 1
U = [[0] * w for _ in range(h)]
for j in range(w):
    for i in range(h):
        # if S[i][j] == '#':
        #     U[i][j] = 0
        if S[i][j] == '.':
            if i == 0:
                U[i][j] = 1
            else:
                U[i][j] = U[i-1][j] + 1
D = [[0] * w for _ in range(h)]
for j in range(w):
    for i in reversed(range(h)):
        # if S[i][j] == '#':
        #     D[i][j] = 0
        if S[i][j] == '.':
            if i == h-1:
                D[i][j] = 1
            else:
                D[i][j] = D[i+1][j] + 1
tmp = [[0] * w for _ in range(h)]
for i in range(h):
    for j in range(w):
        tmp[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):
        ans = max(ans, tmp[i][j])
print(ans)

Submission status: Time Limit Exceeded

Solution code:
h, w = map(int, input().split())
S = [list(input()) for _ in range(h)]
L = [[0] * 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
        else:
            L[i][j] = L[i][j-1] + 1
R = [[0] * w for _ in range(h)]
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
        else:
            R[i][j] = R[i][j+1] + 1
U = [[0] * w for _ in range(h)]
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
        else:
            U[i][j] = U[i-1][j] + 1
D = [[0] * w for _ in range(h)]
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
        else:
            D[i][j] = D[i+1][j] + 1
tmp = [[0] * w for _ in range(h)]
for i in range(h):
    for j in range(w):
        tmp[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):
        ans = max(ans, tmp[i][j])
print(ans)

Submission status: Time Limit Exceeded

Solution code:
h, w = map(int, input().split())
ls = [input().strip() for _ in range(h)]
counts = [[[-1] * w for _ in range(h)] for _ in range(4)]

for y in range(h):
    for x in range(w):
        if ls[y][x] == '#':
            counts[0][y][x] = 0
        else:
            if x == 0:
                counts[0][y][x] = 1
            else:
                counts[0][y][x] = counts[0][y][x - 1] + 1
        yy = h - 1 - y
        xx = w - 1 - x
        if ls[yy][xx] == '#':
            counts[1][yy][xx] = 0
        else:
            if x == 0:
                counts[1][yy][xx] = 1
            else:
                counts[1][yy][xx] = counts[1][yy][xx + 1] + 1

        if ls[y][x] == '#':
            counts[2][y][x] = 0
        else:
            if y == 0:
                counts[2][y][x] = 1
            else:
                counts[2][y][x] = counts[2][y - 1][x] + 1
        yy = h - 1 - y
        xx = w - 1 - x
        if ls[yy][xx] == '#':
            counts[3][yy][xx] = 0
        else:
            if y == 0:
                counts[3][yy][xx] = 1
            else:
                counts[3][yy][xx] = counts[3][yy + 1][xx] + 1

res = 0
for y in range(h):
    for x in range(w):
        val = -3
        for i in range(4):
            val += counts[i][y][x]
        res = max(res, val)

print(res)

Submission status: Time Limit Exceeded

Solution code:
h, w = map(int, input().split())
ls = [input().strip() for _ in range(h)]
counts = [[[-1] * w for _ in range(h)] for _ in range(4)]

for y in range(h):
    for x in range(w):
        if ls[y][x] == '#':
            counts[0][y][x] = 0
        else:
            if x == 0:
                counts[0][y][x] = 1
            else:
                counts[0][y][x] = counts[0][y][x - 1] + 1
        yy = h - 1 - y
        xx = w - 1 - x
        if ls[yy][xx] == '#':
            counts[1][yy][xx] = 0
        else:
            if x == 0:
                counts[1][yy][xx] = 1
            else:
                counts[1][yy][xx] = counts[1][yy][xx + 1] + 1
for x in range(w):
    for y in range(h):
        if ls[y][x] == '#':
            counts[2][y][x] = 0
        else:
            if y == 0:
                counts[2][y][x] = 1
            else:
                counts[2][y][x] = counts[2][y - 1][x] + 1
        yy = h - 1 - y
        xx = w - 1 - x
        if ls[yy][xx] == '#':
            counts[3][yy][xx] = 0
        else:
            if y == 0:
                counts[3][yy][xx] = 1
            else:
                counts[3][yy][xx] = counts[3][yy + 1][xx] + 1

res = 0
for y in range(h):
    for x in range(w):
        val = -3
        for i in range(4):
            val += counts[i][y][x]
        res = max(res, val)

print(res)

Submission status: Time Limit Exceeded

Solution code:
h, w = map(int, input().split())
ls = [input().strip() for _ in range(h)]
counts = [[[-1] * w for _ in range(h)] for _ in range(4)]

for y in range(h):
    for x in range(w):
        if ls[y][x] == '#':
            counts[0][y][x] = 0
        else:
            if x == 0:
                counts[0][y][x] = 1
            else:
                counts[0][y][x] = counts[0][y][x - 1] + 1
for y in range(h - 1, -1, -1):
    for x in range(w - 1, -1, -1):
        if ls[y][x] == '#':
            counts[1][y][x] = 0
        else:
            if x == w - 1:
                counts[1][y][x] = 1
            else:
                counts[1][y][x] = counts[1][y][x + 1] + 1
for x in range(w):
    for y in range(h):
        if ls[y][x] == '#':
            counts[2][y][x] = 0
        else:
            if y == 0:
                counts[2][y][x] = 1
            else:
                counts[2][y][x] = counts[2][y - 1][x] + 1
for x in range(w - 1, -1, -1):
    for y in range(h - 1, -1, -1):
        if ls[y][x] == '#':
            counts[3][y][x] = 0
        else:
            if y == h - 1:
                counts[3][y][x] = 1
            else:
                counts[3][y][x] = counts[3][y + 1][x] + 1

res = 0
for y in range(h):
    for x in range(w):
        val = -3
        for i in range(4):
            val += counts[i][y][x]
        res = max(res, val)

print(res)

Submission status: Time Limit Exceeded

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

for y in range(h):
    left = 0
    while left < w:
        if ls[y][left] == '#':
            left += 1
            continue
        right = left
        while right < w:
            right += 1
            if right == w or ls[y][right] == '#':
                lrs.append([y, left, right, right - left])
                break
        left = right

for x in range(w):
    top = 0
    while top < h:
        if ls[top][x] == '#':
            top += 1
            continue
        bottom = top
        while bottom < h:
            bottom += 1
            if bottom == h or ls[bottom][x] == '#':
                tbs.append([x, top, bottom, bottom - top])
                break
        top = bottom
lrs.sort(key=lambda x: x[3], reverse=True)
tbs.sort(key=lambda x: x[3], reverse=True)

res = 0
for y, left, right, lh in lrs:
    for x, top, bottom, lv in tbs:
        if lh + lv - 1 <= res:
            break
        if top <= y <= bottom and left <= x <= right:
            res = max(res, lh + lv - 1)
            break
print(res)

Submission status: Time Limit Exceeded

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

for y in range(h):
    left = 0
    while left < w:
        if ls[y][left] == '#':
            left += 1
            continue
        right = left
        while right < w:
            right += 1
            if right == w or ls[y][right] == '#':
                lrs.append([y, left, right, right - left])
                break
        left = right

for x in range(w):
    top = 0
    while top < h:
        if ls[top][x] == '#':
            top += 1
            continue
        bottom = top
        while bottom < h:
            bottom += 1
            if bottom == h or ls[bottom][x] == '#':
                tbs.append([x, top, bottom, bottom - top])
                break
        top = bottom
lrs.sort(key=lambda x: x[3], reverse=True)
tbs.sort(key=lambda x: x[3], reverse=True)

res = 0
for y, left, right, lh in lrs:
    for x, top, bottom, lv in tbs:
        if top <= y <= bottom and left <= x <= right:
            res = max(res, lh + lv - 1)
            break
print(res)

Submission status: Time Limit Exceeded

Solution code:
import bisect

h, w = map(int, input().split())
ls = [input().strip() for _ in range(h)]
lrs = [[] for _ in range(h)]
tbs = [[] for _ in range(w)]

for y in range(h):
    left = 0
    while left < w:
        if ls[y][left] == '#':
            left += 1
            continue
        right = left
        while right < w:
            right += 1
            if right == w or ls[y][right] == '#':
                lrs[y].append(left)
                lrs[y].append(right)
                break
        left = right

for x in range(w):
    top = 0
    while top < h:
        if ls[top][x] == '#':
            top += 1
            continue
        bottom = top
        while bottom < h:
            bottom += 1
            if bottom == h or ls[bottom][x] == '#':
                tbs[x].append(top)
                tbs[x].append(bottom)
                break
        top = bottom
res = 0
for y in range(h):
    for x in range(w):
        j = bisect.bisect(lrs[y], x)
        if j % 2 == 0:
            continue
        i = bisect.bisect(tbs[x], y)
        val = lrs[y][j] - lrs[y][j - 1] + tbs[x][i] - tbs[x][i - 1] - 1
        res = max(res, val)
print(res)

Submission status: Time Limit Exceeded

Solution code:
h, w = map(int, input().split())
ls = [input().strip() for _ in range(h)]
xs = [[-1] * w for _ in range(h)]
ys = [[-1] * w for _ in range(h)]
for y in range(h):
    for x in range(w):
        if xs[y][x] >= 0 and ys[y][x] >= 0:
            continue
        if ls[y][x] == '#':
            xs[y][x] = 0
            ys[y][x] = 0
        if xs[y][x] == -1:
            count = 0
            while x + count < w:
                c2 = ls[y][x + count]
                if c2 == '.':
                    count += 1
                else:
                    break
            for i in range(count):
                xs[y][x + i] = count
        if ys[y][x] == -1:
            count = 0
            while y + count < h:
                c2 = ls[y + count][x]
                if c2 == '.':
                    count += 1
                else:
                    break
            for i in range(count):
                ys[y + i][x] = count
res = 0
for y in range(h):
    for x in range(w):
        res = max(res, xs[y][x] + ys[y][x] - 1)
print(res)

Submission status: Time Limit Exceeded

Solution code:
import sys

#+++++

		
def main():
	h , w = map(int, input().split())
	mm=[input() for _ in range(h)]
	
	rr_lr=[[0]*(w) for _ in range(h)]
	rr_rl=[[0]*(w) for _ in range(h)]
	rr_ud=[[0]*(w) for _ in range(h)]
	rr_du=[[0]*(w) for _ in range(h)]
							
	for hi in range(h):
		ll=0
		rl=0
		for wj in range(w):
			if mm[hi][wj] == '.':
				ll+=1
				rr_lr[hi][wj]=ll
			else:
				ll=0				
				
			if mm[hi][w-1-wj] == '.':
				rl+=1
				rr_rl[hi][w-1-wj]=rl
			else:
				rl=0				
					
	for wi in range(w):
		ll=0
		rl=0
		for hj in range(h):
			if mm[hj][wi] == '.':
				ll+=1
				rr_ud[hj][wi]=ll
			else:
				ll=0
				
			if mm[(h-1)-hj][wi] == '.':
				rl+=1
				rr_du[(h-1)-hj][wi]=rl
			else:
				rl=0
				
	ret=0
	for i in range(w):
		for j in range(h):
			vv=rr_lr[j][i]-3
			vv+=rr_rl[j][i]
			vv+=rr_du[j][i]
			vv+=rr_ud[j][i]
			ret = max(ret,vv)
	
	return ret

	
#+++++

if __name__ == "__main__":
	if sys.platform =='ios':
		sys.stdin=open('inputFile.txt')
		isTest=True
	else:
		pass
		input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

Submission status: Time Limit Exceeded

Solution code:
import sys

#+++++

		
def main():
	h , w = map(int, input().split())
	mm=[input() for _ in range(h)]
	
	rr_lr=[[0]*(w) for _ in range(h)]
	rr_rl=[[0]*(w) for _ in range(h)]
	rr_ud=[[0]*(w) for _ in range(h)]
	rr_du=[[0]*(w) for _ in range(h)]
							
	for hi in range(h):
		ll=0
		for wj in range(w):
			if mm[hi][wj] == '.':
				ll+=1
				rr_lr[hi][wj]=ll
			else:
				ll=0				
				
	for hi in range(h):
		ll=0
		for wj in range(w):
			if mm[hi][w-1-wj] == '.':
				ll+=1
				rr_rl[hi][w-1-wj]=ll
			else:
				ll=0				
					
	for wi in range(w):
		ll=0
		for hj in range(h):
			if mm[hj][wi] == '.':
				ll+=1
				rr_ud[hj][wi]=ll
			else:
				ll=0
				
	for wi in range(w):
		ll=0
		for hj in range(h):
			if mm[(h-1)-hj][wi] == '.':
				ll+=1
				rr_du[(h-1)-hj][wi]=ll
			else:
				ll=0
				
	ret=0
	for i in range(w):
		for j in range(h):
			vv=rr_lr[j][i]-3
			vv+=rr_rl[j][i]
			vv+=rr_du[j][i]
			vv+=rr_ud[j][i]
			ret = max(ret,vv)
	
	return ret

	
#+++++

if __name__ == "__main__":
	if sys.platform =='ios':
		sys.stdin=open('inputFile.txt')
		isTest=True
	else:
		pass
		input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

Submission status: Time Limit Exceeded

Solution code:
import sys

sys.setrecursionlimit(2001 * 2001)

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

max_light = 0


def search(x, y, dir):
    if x < 0 or y < 0 or y >= h or x >= w:
        return 0
    if s[y][x] == '#':
        return 0
    if dir == 0:
        return 1 + search(x, y - 1, dir)
    if dir == 1:
        return 1 + search(x + 1, y, dir)
    if dir == 2:
        return 1 + search(x, y + 1, dir)
    if dir == 3:
        return 1 + search(x - 1, y, dir)


def light_search_hol(x, y):
    return search(x, y, 1) + search(x, y, 3)


def light_search_ver(x, y):
    return search(x, y, 0) + search(x, y, 2)


last_hol = 0
last_ver = 0
for i in range(w):
    for j in range(h):
        # hol = 0
        ver = 0
        # hol_fl = 0
        ver_fl = 0
        """
        if i > 1:
            if s[j][i - 1] == '.':
                hol_fl = 1
                hol = last_hol
        """
        if j > 1:
            if s[j - 1][i] == '.':
                ver_fl = 1
                ver = last_ver
        """
        if hol_fl == 0:
            hol = light_search_hol(i, j)
            last_hol = hol
        """
        if ver_fl == 0:
            ver = light_search_ver(i, j)
            last_ver = ver
        hol = light_search_hol(i, j)
        if hol + ver > max_light:
            max_light = hol + ver
            # print('{0} {1}'.format(i, j))

print(max_light-3)

Submission status: Time Limit Exceeded

Solution code:
import sys
sys.setrecursionlimit(2001*2001)

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

max_light = 0


def search(x, y, dir):
    if x < 0 or y < 0 or y >= h or x >= w:
        return 0
    if s[y][x] == '#':
        return 0
    if dir == 0:
        return 1 + search(x, y - 1, dir)
    if dir == 1:
        return 1 + search(x + 1, y, dir)
    if dir == 2:
        return 1 + search(x, y + 1, dir)
    if dir == 3:
        return 1 + search(x - 1, y, dir)


def light_search(x, y):
    return search(x, y, 0) + search(x, y, 1) + search(x, y, 2) + search(x, y, 3)


for i in range(w):
    for j in range(h):
        max_light = max(max_light, light_search(i, j))


print(max_light-3)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
h,w=map(int,input().split())
c=np.array([list(input()) for _ in range(h)])

def lamp(isTrans):
    if isTrans:
        grid=np.transpose(c)
        memo=np.array([[0]*h]*w)
    else:
        grid=c
        memo=np.array([[0]*w]*h)

    H,W=grid.shape

    for i in range(H):
        seen=np.zeros(W, dtype=int)
        for j in range(W):
            if grid[i][j]=="#":
                continue
            if seen[j]:
                continue
            k=0
            while j+k<W:
                if grid[i][j+k]=="#":
                    break
                k+=1
            memo[i][j:j+k]=k
            seen[j:j+k]=1

    if isTrans:
        return np.transpose(memo)
    else:
        return memo

ans=lamp(1)+lamp(0)-1
print(ans.max())

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
h,w=map(int,input().split())
c=np.array([list(input()) for _ in range(h)])
inf=10000

vert=np.zeros((h, w), dtype=int)
hori=np.zeros((h, w), dtype=int)

for x in range(h):
    for y in range(w):
        if c[x][y]=="#":
            vert[x][y]=-inf
            hori[x][y]=-inf
            continue
        
        #vertical
        if vert[x][y]==0:
            v=x
            while v<h and c[v][y]!="#" and vert[v][y]==0:
                v+=1
            vert[x:v, y]=v-x
        #horizontal
        if hori[x][y]==0:
            v=y
            while v<w and c[x][v]!="#" and hori[x][v]==0:
                v+=1
            hori[x, y:v]=v-y

ans=vert+hori-1
print(ans.max())

Submission status: Time Limit Exceeded

Solution code:
import sys

#+++++

def pp_in():
	s=input()
	return '#'+s+'#'
		
def main():
	h , w = map(int, input().split())
	mm=[pp_in() for _ in range(h)]
	ap='#'*(w+2)
	mm=[ap]+mm
	mm.append(ap)
	
	rr=[[[0,0] for _ in range(w+2)] for __ in range(h+2)]
	
	if isTest:
		for r in rr:
			print(r)
		for m in mm:
			print(m)
	
	for hi, hm in enumerate(mm):
		start=-1
		for wj, wc in enumerate(hm):
			if wc == '.' and start == -1:
				#it's new '.' pos.
				start=wj
			elif wc == '.':
				pass
			elif wc == '#' and start == -1:
				pass
			else:
				lb = wj - start
				for ii in range(start, wj):
					rr[hi][ii][0] = lb
				start=-1
	
	for wi in range(w+2):
		start=-1
		for hj in range(h+2):
			cc=mm[hj][wi]
			if cc == '.' and start == -1:
				#it's new '.' pos.
				start=hj
			elif cc == '.':
				pass
			elif cc == '#' and start == -1:
				pass
			else:
				lb = hj - start
				for ii in range(start, hj):
					rr[ii][wi][1] = lb
				start=-1
	
	if isTest:
		for r in rr:
			print(r)
			
	p_ret=max([max([sum(vv) for vv in r]) for r in rr])
	ret=p_ret-1
	return ret

	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)

if __name__ == "__main__":
	if sys.platform =='ios':
		sys.stdin=open('inputFile.txt')
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

Submission status: Time Limit Exceeded

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

L = [[0 for _ in range(w)] for _ in range(h)]
R = [[0 for _ in range(w)] for _ in range(h)]
D = [[0 for _ in range(w)] for _ in range(h)]
U = [[0 for _ in range(w)] for _ in range(h)]

for i in range(h):
  for j in range(w):
    if s[i][j] == '.':
      if j == 0:
        L[i][j] = 1
      else:
        L[i][j] = L[i][j-1]+1     
      if i == 0:
        D[i][j] = 1
      else:
        D[i][j] = D[i-1][j]+1
      if i == h-1:
        U[i][j] = 1
      else:
        U[i][j] = U[i+1][j]+1
  for j in range(w-1, -1, -1):
    if s[i][j] == '.':
      if j == w-1:
        R[i][j] = 1
      else:
        R[i][j] = R[i][j+1]+1

for i in range(h-1, -1, -1):
  for j in range(w):
    if s[i][j] == '.':
      if i == h-1:
        U[i][j] = 1
      else:
        U[i][j] = U[i+1][j]+1
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]-3)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
from collections import deque
h, w = map(int, input().split())
s = [list(input()) for _ in range(h)]
moves = [[0,1], [0,-1],[1,0], [-1,0]]

def bfs(b, a):
  light = [[0 for _ in range(w)] for _ in range(h)]
  q = deque([(b, a, (0, 1, 2, 3))])
  ans = 0
  while q:
    y, x, direction= q.popleft()
    light[y][x] = 1
    ans += 1
    
    for i in direction:
      next_y = y + moves[i][0]
      next_x = x + moves[i][1]
      if 0 <= next_y < h and 0 <= next_x < w and s[next_y][next_x] == '.' and light[next_y][next_x] == 0:
        q.append([next_y, next_x, [i]])
  return ans
final_ans = 0
for i in range(h):
  for j in range(w):
    if s[i][j] == '.':
      final_ans = max(final_ans, bfs(i, j))

print(final_ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
H, W = map(int, input().split())
S = []
for i in range(H):
  ss = input()
  S.append(ss)
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)]
for i in range(H):
  n = -1
  for j in range(W):
    if S[i][j] == "#":
      n = j
    L[i][j] = j-n
  n = W
  for j in reversed(range(W)):
    if S[i][j] == "#":
      n = j
    R[i][j] = n-j
for j in range(W):
  n = -1
  for i in range(H):
    if S[i][j] == "#":
      n = i
    U[i][j] = i-n
  n = H
  for i in reversed(range(H)):
    if S[i][j] == "#":
      n = i
    D[i][j] = n-i
#for i in range(H):
#  print(D[i])
rs = []
for i in range(H):
  for j in range(W):
    if S[i][j] == ".":
      r = L[i][j]+R[i][j]+U[i][j]+D[i][j]-3
      rs.append(r)
r = max(rs)
print(r)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
H, W = map(int, input().split())
S = []
for i in range(H):
  ss = input()
  S.append(ss)
N = [[-1]*W for i in range(H)]
for i in range(H):
  Bs = [-1]
  for j in range(W):
    if S[i][j] == "#":
      Bs.append(j)
  Bs.append(W)
  for k in range(1, len(Bs)):
    n = Bs[k]-Bs[k-1]-1
    for j in range(Bs[k-1]+1, Bs[k]):
      N[i][j] = n
M = [[-1]*W for i in range(H)]
for j in range(W):
  Bs = [-1]
  for i in range(H):
    if S[i][j] == "#":
      Bs.append(i)
  Bs.append(H)
  for k in range(1, len(Bs)):
    n = Bs[k]-Bs[k-1]-1
    for i in range(Bs[k-1]+1, Bs[k]):
      M[i][j] = n
rs = []
for i in range(H):
  for j in range(W):
    if S[i][j] == ".":
      r = N[i][j]+M[i][j]-1
      rs.append(r)
r = max(rs)
print(r)

Submission status: Time Limit Exceeded

Solution code:
def main():
    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 s[i][j]=='.' and j!=w-1:
                now+=1
                continue
            if s[i][j]=='.' and j==w-1:
                now+=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


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

    print(ans-1)

if __name__ == "__main__":
    main()

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 s[i][j]=='.' and j!=w-1:
            now+=1
            continue
        if s[i][j]=='.' and j==w-1:
            now+=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


ans=0
for i in range(w):
    now=0
    for j in range(h):
        if s[j][i]=='.' and j!=h-1:
            now+=1
            continue
        if s[j][i]=='.' and j==h-1:
            now+=1
            for k in range(j+1-now,j+1):
                li[k*w+i][1]=now
                ans=max(ans,sum(li[k*w+i]))
            now=0
        else:
            for k in range(j-now,j):
                li[k*w+i][1]=now
                ans=max(ans,sum(li[k*w+i]))
            now=0
     
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 s[i][j]=='.' and j!=w-1:
            now+=1
            continue
        if s[i][j]=='.' and j==w-1:
            now+=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 s[j][i]=='.' and j!=h-1:
            now+=1
            continue
        if s[j][i]=='.' and j==h-1:
            now+=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)