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:
from collections import defaultdict


class Cell:
    def __init__(self):
        self.is_wall = True
        self.from_t = 0
        self.from_b = 0
        self.from_r = 0
        self.from_l = 0


H, W = map(int, input().split())
grid = defaultdict(lambda: defaultdict(Cell))
for h in range(H):
    for w, c in enumerate(input()):
        grid[h][w].is_wall = c == "#"


for h in range(H):
    from_r = 0
    from_l = 0
    for w in range(W):
        cell = grid[h][w]
        if cell.is_wall:
            from_r = 0
        else:
            from_r += 1
        cell.from_r = from_r

        cell = grid[h][W - 1 - w]
        if cell.is_wall:
            from_l = 0
        else:
            from_l += 1
        cell.from_l = from_l

for w in range(W):
    from_t = 0
    from_b = 0
    for h in range(H):
        cell = grid[h][w]
        if cell.is_wall:
            from_t = 0
        else:
            from_t += 1
        cell.from_t = from_t

        cell = grid[H - 1 - h][w]
        if cell.is_wall:
            from_b = 0
        else:
            from_b += 1
        cell.from_b = from_b

ans = 0
for h in range(H):
    for w in range(W):
        cell = grid[h][w]
        if cell.is_wall:
            continue
        sight = -3
        sight += cell.from_l
        sight += cell.from_r
        sight += cell.from_t
        sight += cell.from_b
        ans = max(ans, sight)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
class Cell:
    def __init__(self, is_wall):
        self.is_wall = is_wall
        self.from_t = 0
        self.from_b = 0
        self.from_r = 0
        self.from_l = 0


H, W = map(int, input().split())
grid = [
    [Cell(c == "#") for c in input()]
    for _ in range(H)
]

for h in range(H):
    from_r = 0
    from_l = 0
    for w in range(W):
        cell = grid[h][w]
        if cell.is_wall:
            from_r = 0
        else:
            from_r += 1
        cell.from_r = from_r

        cell = grid[h][W - 1 - w]
        if cell.is_wall:
            from_l = 0
        else:
            from_l += 1
        cell.from_l = from_l

for w in range(W):
    from_t = 0
    from_b = 0
    for h in range(H):
        cell = grid[h][w]
        if cell.is_wall:
            from_t = 0
        else:
            from_t += 1
        cell.from_t = from_t

        cell = grid[H - 1 - h][w]
        if cell.is_wall:
            from_b = 0
        else:
            from_b += 1
        cell.from_b = from_b

ans = 0
for h in range(H):
    for w in range(W):
        cell = grid[h][w]
        if cell.is_wall:
            continue
        sight = -3
        sight += cell.from_l
        sight += cell.from_r
        sight += cell.from_t
        sight += cell.from_b
        ans = max(ans, sight)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
def D_Lamp():
    h, w = map(int, input().split())
    S = [[] for j in range(h)]
    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 row in range(h):
        S[row] = input()
    for row in range(h):
        for col in range(w):
            if "#" == S[row][col]:
                L[row][col] = 0
            elif col == 0:
                L[row][col] = 1
            elif "." == S[row][col]:
                L[row][col] = L[row][col-1] + 1
    for row in range(h):
        for col in range(w):
            tmp = w-col-1
            if "#" == S[row][tmp]:
                R[row][tmp] = 0
            elif col == 0:
                R[row][tmp] = 1
            elif "." == S[row][tmp]:
                R[row][tmp] = R[row][tmp+1] + 1
    for col in range(w):
        for row in range(h):
            if "#" == S[row][col]:
                U[row][col] = 0
            elif row == 0:
                U[row][col] = 1
            elif "." == S[row][col]:
                U[row][col] = U[row-1][col] + 1
    for col in range(w):
        for row in range(h):
            tmp = h-row-1
            if "#" == S[tmp][col]:
                D[tmp][col] = 0
            elif row == 0:
                D[tmp][col] = 1
            elif "." == S[tmp][col]:
                D[tmp][col] = D[tmp+1][col] + 1
    
    num_max = 0
    for row in range(h):
        for col in range(w):
            s_num = L[row][col] + R[row][col] + U[row][col] + D[row][col] - 3
            num_max = max(num_max, s_num)
    print(num_max)

if __name__ == "__main__":
    D_Lamp()

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

h,w=map(int,input().split())
s=[input() for i in range(h)]

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

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

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

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

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

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys

H,W = list(map(int, input().split()))
S = [[]]*H

for h in range(H):
    S[h] = input()

T = [None]*W

for w in range(W):
    t = [S[h][w] for h in range(H)]
    T[w] = ''.join(t)

#print(S)
#print(T)


def calc_lights_map(MAP, H, W):
    LIGHTS_MAP = [None]*H
    for h in range(H):
        lights_map_row = calc_lights_map_row(MAP[h], W)
        LIGHTS_MAP[h] = lights_map_row
    return LIGHTS_MAP


def calc_lights_map_row(ROW, W):
    lights_map_row = []
    lights = 0
    for here, masu in enumerate(ROW):
        if masu == '#':
            lights_map_row.append(0)
            lights = 0
            continue
        if lights > 0:
            lights_map_row.append(lights)
            continue
        try:
            wall_id = ROW.index('#', here)
        except:
            wall_id = len(ROW)
        lights = wall_id - here
        lights_map_row.append(lights)
        continue
    return lights_map_row

S_lights_map = calc_lights_map(S, H, W)

#print(S)
#print(S_lights_map)

T_lights_map = calc_lights_map(T, W, H)

#print(T)
#print(T_lights_map)


max_lights = 0
for h in range(H):
    for w in range(W):
        lights = S_lights_map[h][w] + T_lights_map[w][h] - 1
        max_lights = max(max_lights, lights)


print(max_lights)

Submission status: Time Limit Exceeded

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

L = [[0 for w in range(W)] for h in range(H)]
for w in range(W):
    for h in range(H):
        s = S[h+1][w+1-1]
        if s == "#":
            L[h][w] = 1
        else:
            L[h][w] = L[h][w-1] + 1

R = [[0 for w in range(W)] for h in range(H)]
for w in range(W-1, -1, -1):
    for h in range(H):
        s = S[h+1][w+1+1]
        if s == "#":
            R[h][w] = 1
        else:
            R[h][w] = R[h][w+1] + 1

U = [[0 for w in range(W)] for h in range(H)]
for w in range(W):
    for h in range(H):
        s = S[h+1-1][w+1]
        if s == "#":
            U[h][w] = 1
        else:
            U[h][w] = U[h-1][w] + 1

D = [[0 for w in range(W)] for h in range(H)]
for w in range(W):
    for h in range(H-1, -1, -1):
        s = S[h+1+1][w+1]
        if s == "#":
            D[h][w] = 1
        else:
            D[h][w] = D[h+1][w] + 1

ret = 0
for w in range(1, W+1):
    for h in range(1, H+1):
        s = S[h][w]
        if s == ".":
            x, y = w-1, h-1
            tmp = L[y][x] + R[y][x] + U[y][x] + D[y][x] - 3
            ret = max(tmp, ret)
            
print(ret)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
import sys
import copy
import collections
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush
import math

# NO, PAY-PAY
#import numpy as np
#import statistics
#from statistics import mean, median,variance,stdev
 
def main():
	H, W = map(int, input().split(" "))
	S = []
	for i in range(H):
		s = list(input())
		S.append(s)
	
	#SS = copy.deepcopy(S)
	SS = rotate_clockwise2(S)
	SS = SS[::-1]
	
	ans = 0
	for i in range(H):
		for j in range(W):
			if S[i][j] == "#":
				continue
			side = get_side(S[i], j)
			
			#V = []
			#for x in range(H):
				#v = S[x][j]
				#V.append(v)
			varti = get_side(SS[j], i)
			
			tmp = side + varti
			tmp -= 1
			if tmp > ans:
				ans = tmp
				
	print(ans)
	
def get_side(S, k):
	total = ''.join(S)
	total = total.split("#")
	
	index = 0
	for i, val in enumerate(total):
		index += len(val)
		if k <= index:
			return len(val)
		index += 1
	
def rotate_clockwise2(matrix):
    return list(map(list, zip(*matrix)))[::-1]
	
if __name__ == "__main__":
	main()

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
import sys
import copy
import collections
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush
import math

# NO, PAY-PAY
#import numpy as np
#import statistics
#from statistics import mean, median,variance,stdev
 
def main():
	H, W = map(int, input().split(" "))
	S = []
	for i in range(H):
		s = list(input())
		S.append(s)
	
	SS = copy.deepcopy(S)
	SS = rotate_clockwise2(S)
	SS = SS[::-1]
	
	ans = 0
	for i in range(H):
		for j in range(W):
			if S[i][j] == "#":
				continue
			side = get_side(S[i], j)
			
			#V = []
			#for x in range(H):
				#v = S[x][j]
				#V.append(v)
			varti = get_side(SS[j], i)
			
			tmp = side + varti
			tmp -= 1
			if tmp > ans:
				ans = tmp
				
	print(ans)
	
def get_side(S, k):
	total = ''.join(S)
	total = total.split("#")
	
	index = 0
	for i, val in enumerate(total):
		index += len(val)
		if k <= index:
			return len(val)
		index += 1
	
def rotate_clockwise2(matrix):
    return list(map(list, zip(*matrix)))[::-1]
	
if __name__ == "__main__":
	main()

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
import sys
import copy
import collections
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush
import math

# NO, PAY-PAY
#import numpy as np
#import statistics
#from statistics import mean, median,variance,stdev
 
def main():
	H, W = map(int, input().split(" "))
	S = []
	for i in range(H):
		s = list(input())
		S.append(s)
	
	SS = []
	for w in range(W):
		V = []
		for h in range(H):
			v = S[h][w]
			V.append(v)
		SS.append(V)
	
	ans = 0
	for i in range(H):
		for j in range(W):
			if S[i][j] == "#":
				continue
			side = get_side(S[i], j)
			
			#V = []
			#for x in range(H):
				#v = S[x][j]
				#V.append(v)
			varti = get_side(SS[j], i)
			
			tmp = side + varti
			tmp -= 1
			if tmp > ans:
				ans = tmp
				
	print(ans)
	
def get_side(S, k):
	total = ''.join(S)
	total = total.split("#")
	
	index = 0
	for i, val in enumerate(total):
		index += len(val)
		if k <= index:
			return len(val)
		index += 1
	
if __name__ == "__main__":
	main()

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
import sys
import copy
import collections
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush
import math

# NO, PAY-PAY
#import numpy as np
#import statistics
#from statistics import mean, median,variance,stdev
 
def main():
	H, W = map(int, input().split(" "))
	S = []
	for i in range(H):
		s = list(input())
		S.append(s)
	
	ans = 0
	for i in range(H):
		for j in range(W):
			if S[i][j] == "#":
				continue
			side = get_side(S[i], j)
			
			V = []
			for x in range(H):
				v = S[x][j]
				V.append(v)
			varti = get_side(V, i)
			
			tmp = side + varti
			tmp -= 1
			if tmp > ans:
				ans = tmp
				
	print(ans)
	
def get_side(S, k):
	total = ''.join(S)
	total = total.split("#")
	
	index = 0
	for i, val in enumerate(total):
		index += len(val)
		if k <= index:
			return len(val)
		index += 1
	
if __name__ == "__main__":
	main()

Submission status: Time Limit Exceeded

Solution code:
class UnionFind():
    def __init__(self, n):
        self.parent = [-1 for _ in range(n)]
        # 正==子: 根の頂点番号 / 負==根: 連結頂点数

    def find(self, x):
        if self.parent[x] < 0:
            return x
        else:
            self.parent[x] = self.find(self.parent[x])
            return self.parent[x]

    def unite(self, x, y):
        x, y = self.find(x), self.find(y)
        if x == y:
            return False
        else:
            if self.size(x) < self.size(y):
                x, y = y, x
            self.parent[x] += self.parent[y]
            self.parent[y] = x

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def size(self, x):
        x = self.find(x)
        return -self.parent[x]


h, w = map(int, input().split())
s = tuple(input() for _ in range(h))

uf_v = UnionFind(h * w)
uf_h = UnionFind(h * w)

for r in range(h):
    for c in range(w):
        if s[r][c] == '#': continue
        for dr in (-1, 1):
            nr = r + dr
            if 0 <= nr < h:
                if s[nr][c] == '.':
                    x = r * w + c
                    nx = nr * w + c
                    uf_v.unite(x, nx)
        for dc in (-1, 1):
            nc = c + dc
            if 0 <= nc < w:
                if s[r][nc] == '.':
                    x = r * w + c
                    nx = r * w + nc
                    uf_h.unite(x, nx)

ans = 0
for r in range(h):
    for c in range(w):
        x = r * w + c
        ans = max(ans, uf_v.size(x) + uf_h.size(x) - 1)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sat Jul 13 15:36:35 2019
ABC129D
@author: maezawa
"""

h, w = list(map(int, input().split()))
arr = [['*']*(w+2)]
for _ in range(h):
    arr.append(list('*' +input()+'*'))
arr.append(['*']*(w+2))

#result = arr[:]
#print(arr)

left = [[0]*(w+2) for _ in range(h+2)]
right = [[0]*(w+2) for _ in range(h+2)]
up = [[0]*(w+2) for _ in range(h+2)]
down = [[0]*(w+2) for _ in range(h+2)]

for i in range(1, h+1):
    for j in range(1, w+1):
        if arr[i][j] == '#':
            left[i][j] = 0
        else:
            left[i][j] = left[i][j-1] + 1
for i in range(1, h+1):
    for j in reversed(range(1, w+1)):
        if arr[i][j] == '#':
            right[i][j] = 0
        else:
            right[i][j] = right[i][j+1] + 1
            
#print(left,sep='\n')
#print(right,sep='\n')

for j in range(1, w+1):
    for i in range(1, h+1):
        if arr[i][j] == '#':
            down[i][j] = 0
        else:
            down[i][j] = down[i-1][j] + 1
for j in range(1, w+1):
    for i in reversed(range(1, h+1)):
        if arr[i][j] == '#':
            up[i][j] = 0
        else:
            up[i][j] = up[i+1][j] + 1
            
maxlight = 0
for i in range(1,h+1):
    for j in range(1,w+1):
        if arr[i][j] == '#':
            continue
        n = left[i][j] + right[i][j] + up[i][j] + down[i][j] - 3
        #result[i][j] = n
        if n > maxlight:
            maxlight = n
            
print(maxlight)

Submission status: Time Limit Exceeded

Solution code:
h,w=map(int,input().split())
a = []
for i in range(h):
  l = input()
  l = list(l)
  a.append(l)
arrh = []
arrw = []
for i in range(w):
  arr = []
  c = 0
  k = 0
  while k < h:
    if a[k][i] == "#":
      for j in range(c):
        arr.append(c)
      arr.append(0)
      c = 0
    elif a[k][i] == "." and k == h - 1:
      for j in range(c+1):
        arr.append(c+1)
    elif a[k][i] == ".":
      c += 1
    k += 1
  arrh.append(arr)
for i in range(h):
  arr = []
  c = 0
  k = 0
  while k < w:
    if a[i][k] == "#":
      for j in range(c):
        arr.append(c)
      arr.append(0)
      c = 0
    elif a[i][k] == "." and k == w - 1:
      for j in range(c+1):
        arr.append(c+1)
    elif a[i][k] == ".":
      c += 1
    k += 1
  arrw.append(arr)
arrf = []
for i in range(h):
  for j in range(w):
    arrf.append(arrh[j][i] + arrw[i][j] - 1)
print(max(arrf))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np


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

grid = list()
for _ in range(H):
    grid.append(input())

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

for col in range(W):
    cnt = 0
    for row in range(H):
        if grid[row][col] == '.':
            cnt += 1
        else:
            cnt = 0
        up[row][col] = cnt
for col in range(W):
    cnt = 0
    for row in reversed(range(H)):
        if grid[row][col] == '.':
            cnt += 1
        else:
            cnt = 0
        down[row][col] = cnt
for row in range(H):
    cnt = 0
    for col in range(W):
        if grid[row][col] == '.':
            cnt += 1
        else:
            cnt = 0
        left[row][col] = cnt
for row in range(H):
    cnt = 0
    for col in reversed(range(W)):
        if grid[row][col] == '.':
            cnt += 1
        else:
            cnt = 0
        right[row][col] = cnt

print(np.max(up + down + left + right) - 3)

Submission status: Time Limit Exceeded

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

grid = list()
for _ in range(H):
    grid.append(input())

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

for col in range(W):
    cnt = 0
    for row in range(H):
        if grid[row][col] == '.':
            cnt += 1
        else:
            cnt = 0
        up[row][col] = cnt
for col in range(W):
    cnt = 0
    for row in reversed(range(H)):
        if grid[row][col] == '.':
            cnt += 1
        else:
            cnt = 0
        down[row][col] = cnt
for row in range(H):
    cnt = 0
    for col in range(W):
        if grid[row][col] == '.':
            cnt += 1
        else:
            cnt = 0
        left[row][col] = cnt
for row in range(H):
    cnt = 0
    for col in reversed(range(W)):
        if grid[row][col] == '.':
            cnt += 1
        else:
            cnt = 0
        right[row][col] = cnt

ans = 0
for i in range(H):
    for j in range(W):
        if grid[i][j] == '#':
            continue
        lighted = up[i][j] + down[i][j] + left[i][j] + right[i][j] - 3
        ans = max(ans, lighted)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from itertools import accumulate

def solve():
    def getNums(Ss):
        lenS = len(Ss)
        nums = [0] * lenS
        Ss += '#'
        num = -1
        for i, S in enumerate(Ss):
            if S == '.':
                num += 1
            else:
                if num > 0:
                    nums[i-(num+1)] = num
                    if i < lenS:
                        nums[i] = -num
                num = -1
        return accumulate(nums)


    H, W = map(int, input().split())
    Sss = [input() for _ in range(H)]

    numHss = [list(getNums(Ss)) for Ss in Sss]
    Sss_tr = list(map(''.join, zip(*Sss))) # 転置
    numVss_tr = [getNums(Ss) for Ss in Sss_tr]
    numVss = list(map(list, zip(*numVss_tr))) # 転置

    ans = 0
    for i in range(H):
        for j in range(W):
            num = numHss[i][j] + numVss[i][j] + 1
            if num > ans:
                ans = num

    print(ans)

solve()

Submission status: Time Limit Exceeded

Solution code:
H,W=map(int,input().split())
s=[0 for j in range(H)]
for i in range(H):
  s[i]=str(input())
  s[i]=[j for j in s[i]]
a=0
for i in range(H):
  for j in range(W):
    count=0
    k=i
    while k>-1 and s[k][j]=='.':
      count=count+1
      k=k-1
    k=i
    while k<H and s[k][j]=='.':
      count=count+1
      k=k+1
    k=j
    while k>-1 and s[i][k]=='.':
      count=count+1
      k=k-1
    k=j
    while k<W and s[i][k]=='.':
      count=count+1
      k=k+1
    if count-3 > a:
      a=count-3
print(a)

Submission status: Time Limit Exceeded

Solution code:
H,W=map(int,input().split())
s=[0 for j in range(H)]
for i in range(H):
  s[i]=str(input())
  s[i]=[j for j in s[i]]
t=[[0 for i in range(W)] for j in range(H)]
for i in range(H):
  for j in range(W):
    count=0
    k=i
    while k>-1 and s[k][j]=='.':
      count=count+1
      k=k-1
    k=i
    while k<H and s[k][j]=='.':
      count=count+1
      k=k+1
    k=j
    while k>-1 and s[i][k]=='.':
      count=count+1
      k=k-1
    k=j
    while k<W and s[i][k]=='.':
      count=count+1
      k=k+1
    t[i][j]=count-3
a=[0]*H
for i in range(H):
  a[i]=max(t[i])
print(max(a))

Submission status: Time Limit Exceeded

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

def pri(tbl, tbl2, tbl3, tbl4, n, m):
	for i in range(n):
		for j in range(m):
			print("{:2}".format(tbl[i][j]+tbl2[i][j]+tbl3[i][j]+tbl4[i][j]), end='')
		print('')
	print('')

def main():
	n, m = map(int, input().strip().split())
	v = []
	for i in range(n):
		v.append(input().strip())
	tbl = [[0] * m for _ in range(n)]
	tbl2 = [[0] * m for _ in range(n)]
	tbl3 = [[0] * m for _ in range(n)]
	tbl4 = [[0] * m for _ in range(n)]
	for i in range(n):
		for j in range(m):
			if v[i][j] == '#':
				tbl[i][j] = -1
			elif j == 0:
				continue
			else:
				tbl[i][j] = tbl[i][j-1] + 1
	# pri(tbl, tbl2, tbl3, tbl4, n, m)
	for i in range(n):
		for j in range(m-1, -1, -1):
			if v[i][j] == '#':
				tbl2[i][j] = -1
			elif j == m-1:
				continue
			else:
				tbl2[i][j] = tbl2[i][j+1] + 1
	# pri(tbl, tbl2, tbl3, tbl4, n, m)

	
	for j in range(m):
		for i in range(n):
			if v[i][j] == '#':
				tbl3[i][j] = -1
			elif i == 0:
				continue
			else:
				tbl3[i][j] = tbl3[i-1][j] + 1
	for j in range(m):
		for i in range(n-1, -1, -1):
			if v[i][j] == '#':
				tbl4[i][j] = -1
			elif i == n-1:
				continue
			else:
				tbl4[i][j] = tbl4[i+1][j] + 1
	# for i in range(n):
	# 	print(tbl[i])
	# pri(tbl, tbl2, tbl3, tbl4, n, m)
	ans = 0
	for i in range(n):
		for j in range(m):
			ans = max(ans, tbl[i][j]+tbl2[i][j]+tbl3[i][j]+tbl4[i][j])
	print(ans+1)

if __name__ == '__main__':
	main()

Submission status: Time Limit Exceeded

Solution code:
H, W = map(int, input().split())
S = [input() for _ in range(H)]
a = 0
for h in range(H):
  for w in range(W):
    if S[h][w] == '#':
      continue
    t, b, l, r = h, h, w, w
    while t > 0 and S[t - 1][w] == '.':
      t -= 1
    while b < H - 1 and S[b + 1][w] == '.':
      b += 1
    while l > 0 and S[h][l - 1] == '.':
      l -= 1
    while r < W - 1 and S[h][r + 1] == '.':
      r += 1
    a = max(a, b - t + r - l + 1)
print(a)

Submission status: Time Limit Exceeded

Solution code:
def larger(x, y):
	if x > y:
		return x
	return y

H, W = map(int, input().split())
field = []
for i in range(0, H):
	field.append(input())
upper = []
down = []
left = []
right = []
for i in range(0, H):
	lst1 = []
	lst2 = []
	lst3 = []
	lst4 = []
	for j in range(0, W):
		lst1.append(0)
		lst2.append(0)
		lst3.append(0)
		lst4.append(0)
	upper.append(lst1)
	down.append(lst2)
	left.append(lst3)
	right.append(lst4)
for i in range(0, H):
	for j in range(0, W):
		if field[i][j] == '.':
			
			for k in range(1, H):
				if i - k < 0:
					break
				if field[i-k][j] == '#':
					break
				upper[i][j] += 1
			for k in range(1, H):
				if i + k >= H:
					break
				if field[i+k][j] == '#':
					break
				down[i][j] += 1
			for k in range(1, W):
				if j - k < 0:
					break
				if field[i][j-k] == '#':
					break
				left[i][j] += 1
			for k in range(1, W):
				if j + k >= W:
					break
				if field[i][j+k] == '#':
					break
				right[i][j] += 1
max = 0
for i in range(0, H):
	for j in range(0, W):
		if field[i][j] == '.':
			lamp = upper[i][j] + down[i][j] + left[i][j] + right[i][j] + 1
			max = larger(max, lamp)
print(max)

Submission status: Time Limit Exceeded

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

S = [[0] * W for _ in range(H)]
for i in range(H):
    for j in range(W):
        if M[i][j] == ".":
            if j > 0:
                S[i][j] = S[i][j - 1] + 1
            else:
                S[i][j] = 1
    for j in range(W - 2, -1, -1):
        S[i][j] = max(S[i][j], S[i][j + 1]) * (1 if S[i][j] else 0)

T = [[0] * W for _ in range(H)]
for j in range(W):
    for i in range(H):
        if M[i][j] == ".":
            if i > 0:
                T[i][j] = T[i - 1][j] + 1
            else:
                T[i][j] = 1
    for i in range(H - 2, -1, -1):
        T[i][j] = max(T[i][j], T[i + 1][j]) * (1 if T[i][j] else 0)

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

Submission status: Time Limit Exceeded

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

ans = 0
for i in range(H):
	for j in range(W):
		if S[i][j] == ".":
			U, R, D, L = 0, 0, 0, 0
			while i - U >= 0 and S[i - U][j] == ".":
				U += 1
			while i + D <= H - 1 and S[i + D][j] == ".":
				D += 1
			while j + R <= W - 1 and S[i][j + R] == ".":
				R += 1
			while j - L >= 0 and S[i][j - L] == ".":
				L += 1
			ans = max(ans, L + R + D + U - 3)
print(ans)

Submission status: Time Limit Exceeded

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

L = [[0] * W for _ in range(H)]
R = [[0] * W for _ in range(H)]
D = [[0] * W for _ in range(H)]
U = [[0] * 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

# print(L)

for i in range(H):
	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

# print(R)

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

# print(D)

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

# print(U)


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

# print(X)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
H, W = map(int, input().split())
obs = [[False for _ in range(W)] for _ in range(H)]
for y in range(H):
    s = input()
    for x in range(W):
        obs[y][x] = (s[x] == '#')

inc_x = [[0 for _ in range(W)] for _ in range(H)]
cnt_x = [[0 for _ in range(W)] for _ in range(H)]
for y in range(H):
    for x in range(W):
        if obs[y][x]: 
            inc_x[y][x]= 0
        elif x == 0 or obs[y][x-1]:
            inc_x[y][x] = 1
        else:
            inc_x[y][x] = inc_x[y][x-1] + 1
    for x in reversed(range(W)):
        if obs[y][x]:
            cnt_x[y][x]= 0
        elif x == W-1 or obs[y][x+1]:
            cnt_x[y][x] = inc_x[y][x]
        else:
            cnt_x[y][x] += cnt_x[y][x+1]

inc_y = [[0 for _ in range(W)] for _ in range(H)]
cnt_y = [[0 for _ in range(W)] for _ in range(H)]
for x in range(W):
    for y in range(H):
        if obs[y][x]: 
            inc_y[y][x]= 0
        elif y == 0 or obs[y-1][x]:
            inc_y[y][x] = 1
        else:
            inc_y[y][x] = inc_y[y-1][x] + 1
    for y in reversed(range(H)):
        if obs[y][x]:
            cnt_y[y][x]= 0
        elif y == H-1 or obs[y+1][x]:
            cnt_y[y][x] = inc_y[y][x]
        else:
            cnt_y[y][x] += cnt_y[y+1][x]


cnt = [[cnt_x[y][x]+cnt_y[y][x]-1 for x in range(W)] for y in range(H)]
ans = max([max(cnt[y]) for y in range(H)])
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

H, W = map(int, input().split())
obs = [[False for _ in range(W)] for _ in range(H)]
for y in range(H):
    s = input()
    for x in range(W):
        obs[y][x] = (s[x] == '#')

inc_x = [[0 for _ in range(W)] for _ in range(H)]
cnt_x = [[0 for _ in range(W)] for _ in range(H)]
for y in range(H):
    for x in range(W):
        if obs[y][x]: 
            inc_x[y][x]= 0
        elif x == 0 or obs[y][x-1]:
            inc_x[y][x] = 1
        else:
            inc_x[y][x] = inc_x[y][x-1] + 1
    for x in reversed(range(W)):
        if obs[y][x]:
            cnt_x[y][x]= 0
        elif x == W-1 or obs[y][x+1]:
            cnt_x[y][x] = inc_x[y][x]
        else:
            cnt_x[y][x] += cnt_x[y][x+1]

inc_y = [[0 for _ in range(W)] for _ in range(H)]
cnt_y = [[0 for _ in range(W)] for _ in range(H)]
for x in range(W):
    for y in range(H):
        if obs[y][x]: 
            inc_y[y][x]= 0
        elif y == 0 or obs[y-1][x]:
            inc_y[y][x] = 1
        else:
            inc_y[y][x] = inc_y[y-1][x] + 1
    for y in reversed(range(H)):
        if obs[y][x]:
            cnt_y[y][x]= 0
        elif y == H-1 or obs[y+1][x]:
            cnt_y[y][x] = inc_y[y][x]
        else:
            cnt_y[y][x] += cnt_y[y+1][x]


cnt = np.amax(np.array([[cnt_x[y][x]+cnt_y[y][x] for x in range(W)] for y in range(H)])) - 1
print(cnt)