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: Runtime Error

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

def calc(s):
    res = []
    for v in s:
        v.append('-')
        tmp = []
        nc = ''
        nn = 0
        for c in v:
            if nc == '':
                nc = c
                nn += 1
                continue
            if nc == c:
                nn += 1
                continue
            else:
                if nc == '#':
                    tmp.extend([0 for _ in range(nn)])
                else:
                    tmp.extend( [nn for _ in range(nn)])
        res.append(tmp)
    return res

def calc2(s):
    res = []
    for j in range(w):
        tmp = []
        nc = ''
        nn = 0
        for i in range(h+1):
            if i == h:
                c = '-'
            else:
                c = s[i][j]
            if nc == '':
                nc = c
                nn += 1
                continue
            if nc == c:
                nn += 1
                continue
            else:
                if nc == '#':
                    tmp.extend([0 for _ in range(nn)])
                else:
                    tmp.extend( [nn for _ in range(nn)])
                nc = c
                nn = 1
        res.append(tmp)
    return res

tate = calc2(S)
yoko = calc(S)

print(max([tate[j][i] + yoko[i][j] for i in range(h) for j in range(w) if tate[j][i] * yoko[i][j] != 0]) - 1)

Submission status: Runtime Error

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

def calc(s):
    res = []
    for v in s:
        v.append('-')
        tmp = []
        nc = ''
        nn = 0
        for c in v:
            if nc == '':
                nc = c
                nn += 1
                continue
            if nc == c:
                nn += 1
                continue
            else:
                if nc == '#':
                	tmp.extend([0 for _ in range(nn)])
                else:
                	tmp.extend( [nn for _ in range(nn)])
        res.append(tmp)
    return res

def calc2(s):
    res = []
    for j in range(w):
        tmp = []
        nc = ''
        nn = 0
        for i in range(h+1):
            if i == h:
                c = '-'
            else:
                c = s[i][j]
            if nc == '':
                nc = c
                nn += 1
                continue
            if nc == c:
                nn += 1
                continue
            else:
                if nc == '#':
                	tmp.extend([0 for _ in range(nn)])
            	else:
                	tmp.extend( [nn for _ in range(nn)])
                nc = c
                nn = 1
        res.append(tmp)
    return res

tate = calc2(S)
yoko = calc(S)
print(max([tate[j][i] + yoko[i][j] for i in range(h) for j in range(w) if tate[j][i] * yoko[i][j] != 0]) - 1)

Submission status: Runtime Error

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

def calc(s):
    res = []
    for v in s:
        v.append('-')
        tmp = []
        nc = ''
        nn = 0
        for c in v:
            if nc == '':
                nc = c
                nn += 1
                continue
            if nc == c:
                nn += 1
                continue
            else:
                if nc == '#':
                    tmp = tmp + [0 for _ in range(nn)]
                else:
                    tmp = tmp + [nn for _ in range(nn)]
                nc = c
                nn = 1
        res.append(tmp)
    return res

def calc2(s):
    res = []
    for j in range(w):
        v = ['-']
        tmp = []
        nc = ''
        nn = 0
        for i in range(h+1):
            if i == h:
                c = '-'
            else:
                c = s[i][j]
            if nc == '':
                nc = c
                nn += 1
                continue
            if nc == c:
                nn += 1
                continue
            else:
                if nc == '#':
                    tmp = tmp + [0 for _ in range(nn)]
                else:
                    tmp = tmp + [nn for _ in range(nn)]
                nc = c
                nn = 1
        res.append(tmp)
    return res

tate = np.asarray(calc2(S)).T
yoko = np.asarray(calc(S))
print((tate + yoko).max() - 1)

Submission status: Runtime Error

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

def calc(s):
    res = []
    for v in s:
        v.append('-')
        tmp = []
        nc = ''
        nn = 0
        for c in v:
            if nc == '':
                nc = c
                nn += 1
                continue
            if nc == c:
                nn += 1
                continue
            else:
                if nc == '#':
                    tmp = tmp + [0 for _ in range(nn)]
                else:
                    tmp = tmp + [nn for _ in range(nn)]
                nc = c
                nn = 1
        res.append(tmp)
    return res

def calc2(s):
    res = []
    for j in range(w):
        v = ['-']
        tmp = []
        nc = ''
        nn = 0
        for i in range(h+1):
            if i == h:
                c = '-'
            else:
                c = s[i][j]
            if nc == '':
                nc = c
                nn += 1
                continue
            if nc == c:
                nn += 1
                continue
            else:
                if nc == '#':
                    tmp = tmp + [0 for _ in range(nn)]
                else:
                    tmp = tmp + [nn for _ in range(nn)]
                    nc = c
                    nn = 1
        res.append(tmp)
    return res

tate = calc2(S)
yoko = calc(S)
print(max([tate[j][i] + yoko[i][j] for i in range(h) for j in range(w) if tate[j][i] * yoko[i][j] != 0]) - 1)

Submission status: Runtime Error

Solution code:
#import sys
#sys.setrecursionlimit(100)
'''
allinputs = iter(input().splitlines())
input = lambda : next(allinputs)
#'''
H, W = map(int, input().split())
S = [input() for _ in range(H)]

dx = [-1, 1, 0, 0]
dy = [0, 0, -1, 1]

def dfs(x, y, count, i):
	nx = x + dx[i]
	ny = y + dy[i]
	if nx >= 0 and nx < H and ny >= 0 and ny < W and S[nx][ny] == '.':
		return dfs(nx, ny, count + 1, i)
	else:
		return count
		
ans = 0

for sx in range(H):
	for sy in range(W):
		if S[sx][sy] == '.':
			tmp = 1
			for i in range(4):
				tmp += dfs(sx, sy, 0, i)
				
			if tmp > ans:
				ans = tmp
				
print(ans)

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(2000)
'''
allinputs = iter(input().splitlines())
input = lambda : next(allinputs)
#'''
H, W = map(int, input().split())
S = [input() for _ in range(H)]

dx = [-1, 1, 0, 0]
dy = [0, 0, -1, 0]

def dfs(x, y, count, i):
	nx = x + dx[i]
	ny = y + dy[i]
	if nx >= 0 and nx < H and ny >= 0 and ny < W and S[nx][ny] == '.':
		return dfs(nx, ny, count + 1, i)
	else:
		return count
		
ans = 0

for sx in range(H):
	for sy in range(W):
		if S[sx][sy] == '.':
			tmp = 1
			for i in range(4):
				tmp += dfs(sx, sy, 0, i)
				
			if tmp > ans:
				ans = tmp
				
print(ans)

Submission status: Runtime Error

Solution code:
from functools import reduce
import sys
import numpy as np
MOD = 1000000007

buffer = sys.stdin.buffer
H, W = list(map(int,buffer.readline().split()))
S = np.frombuffer(buffer.read(H*(W+2)), dtype="B") == ord(".")
S = S.reshape((H,W+2))[:,:-2]
L = np.empty((H,W), dtype="i4")
R = np.empty((H,W), dtype="i4")
U = np.empty((H,W), dtype="i4")
D = np.empty((H,W), dtype="i4")
 
L[:,0] = S[:,0]
for i in range(1,W):
    L[:,i] = (L[:,i-1] + 1) * S[:,i]
 
R[:,-1] = S[:,-1]
for i in range(1,W):
    R[:,-1-i] = (R[:,-i] + 1) * S[:,-1-i]
 
U[0] = S[0]
for i in range(1,H):
    U[i] = (U[i-1] + 1) * S[i]
 
D[-1] = S[-1]
for i in range(1,H):
    D[-1-i] = (D[-i] + 1) * S[-1-i]
 
score = L + R + U + D - 3
print(int(score.max()))

Submission status: Runtime Error

Solution code:
import numpy as np

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

s = [list(input().rstrip()) for _ in range(h)]

left = np.zeros((h + 2, w + 2))
right = np.zeros((h + 2, w + 2))
up = np.zeros((h + 2, w + 2))
down = np.zeros((h + 2, w + 2))

ans = 0
for r, c in ((r, c) for r in range(1, h + 1) for c in range(1, w + 1)):
    r_r, c_r = h + 1 - r, w + 1 - c
    if s[r - 1][c - 1] == '.':
        left[r][c] = left[r][c - 1] + 1
        up[r][c] = up[r - 1][c] + 1
    if s[r_r - 1][c_r - 1] == '.':
        right[r_r][c_r] = right[r_r][c_r + 1] + 1
        down[r_r][c_r] = down[r_r + 1][c_r] + 1


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

Submission status: Runtime Error

Solution code:
import numpy as np

Height, Width = map(int,input().split(" "))

lineBlocks = [(input()) for i in range(Height)]

twoDimMap = []
for Block in lineBlocks:
  twoDimMap.append(list(Block))
  
ansList = []
heightList = np.zeros((Height, Width), dtype=int)
widthList  = np.zeros((Height, Width), dtype=int)

for i in range(Height):
  for j in range(Width):
    
    if '#' == twoDimMap[i][j]:
      continue

    else:
        if heightList[i][j] == 0:

            k_up = i+1
            height_len = 0
            while( k_up < Height and twoDimMap[k_up][j] != "#"):
                height_len += 1
                k_up += 1
                
            
            k_down = i-1
            while( k_down >= 0 and twoDimMap[k_down][j] != "#"):
                height_len += 1
                k_down -= 1
            
            for k in range(k_down+1,k_up):
                heightList[k][i] = height_len


        if widthList[i][j] == 0:
            k_right = j+1
            width_len = 0
            while(k_right < Width and twoDimMap[i][k_right] != "#"):
                width_len += 1
                k_right += 1

            k_left = j-1
            while(k_left >= 0 and twoDimMap[i][k_left] != "#"):
                width_len += 1
                k_left -= 1
            
            for k in range(k_left+1,k_right):
                widthList[i][k] = width_len

print(np.array(heightList + widthList + 1).max())

Submission status: Runtime Error

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

def cnt(l, o = 0):
	if len(l) == 1:
		return [1] if l[0] == '.' else [0]
	
	k = cnt(l[1:],o+1)
	if l[0] == '.':
		if k[0] == 0:
			k.insert(0, o+1)
		else:
			k.insert(0, k[0])
	else:
		k.insert(0,0)
	
	return k
	
def trans(t):
	w = len(t[0])
	return [[l[i] for l in t] for i in range(w)]
	
yoko = [cnt(i) for i in s]
tate = trans([cnt(i) for i in trans(s)])

yoko = sum(yoko, [])
tate = sum(tate, [])

print(max((yoko[i] + tate[i] for i in range(len(yoko)))) - 1)

Submission status: Runtime Error

Solution code:
def U(x,y):
    if List[y][x]=="#":
        return(0)
    elif y==0:
        return(1)
    else:
        return(U(x,y-1)+1)

def D(x,y):
    if List[y][x]=="#":
        return(0)
    elif y==H-1:
        return(1)
    else:
        return(D(x,y+1)+1)

def R(x,y):
    if List[y][x]=="#":
        return(0)
    elif x==W-1:
        return(1)
    else:
        return(R(x+1,y)+1)

def L(x,y):
    if List[y][x]=="#":
        return(0)
    elif x==0:
        return(1)
    else:
        return(L(x-1,y)+1)

ans,List=0,[]
H,W=map(int,input().split())
for _ in range(H):
    List.append(list(input()))

for y in range(H):
    for x in range(W):
        if List[y][x]=="#":
            pass
        elif ans<=U(x,y)+D(x,y)+R(x,y)+L(x,y)-3:
            ans=U(x,y)+D(x,y)+R(x,y)+L(x,y)-3
        else:
            pass

print(ans)

Submission status: Runtime Error

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

def cnt(l, o):
	if len(l) == 1:
		if l == ".":
			return [o + 1]
		elif l == "#":
			return [0]
	if l[0] == ".":
		k = cnt(l[1:], o + 1)
		if k[0] == 0:
			k.insert(0, o + 1)
		else:
			k.insert(0, k[0])
		return k
	elif l[0] == "#":
		k = cnt(l[1:], 0)
		k.insert(0, 0)
		return k

def trans(s):
	w = len(s[0])
	return ["".join(l[i] for l in s) for i in range(w)]
	
def transt(s):
	w = len(s[0])
	return [[l[i] for l in s] for i in range(w)]
			
yoko = [cnt(i,0) for i in s]
tate = transt([cnt(i,0) for i in trans(s)])

yoko = sum(yoko,[])
tate = sum(tate,[])

print(max(yoko[i] + tate[i] for i in range(len(yoko)))-1)

Submission status: Runtime Error

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

def cnt(l, o):
	if len(l) == 1:
		if l == ".":
			return [o + 1]
		elif l == "#":
			return [0]
	if l[0] == ".":
		k = cnt(l[1:], o + 1)
		if k[0] == 0:
			k.insert(0, o + 1)
		else:
			k.insert(0, k[0])
		return k
	elif l[0] == "#":
		k = cnt(l[1:], 0)
		k.insert(0, 0)
		return k

def trans(s):
	w = len(s[0])
	return ["".join(l[i] for l in s) for i in range(w)]
	
def transt(s):
	w = len(s[0])
	return [[l[i] for l in s] for i in range(w)]
			
yoko = [cnt(i,0) for i in s]
tate = transt([cnt(i,0) for i in trans(s)])

yoko = sum(yoko,[])
tate = sum(tate,[])

print(max(yoko[i] + tate[i] for i in range(len(yoko))))

Submission status: Runtime Error

Solution code:
h, w = map(int, raw_input().split())
S = [raw_input() for i in range(h)]
Gh = [[0]*w for i in range(h)]
Gw = [[0]*w for i in range(w)]

for i in range(h):
    ps = 0
    s = S[i]
    for j in range(w):
        if s[j] == "#":
            ps = 0
        else:
            ps += 1
            Gh[i][j] = ps

for j in range(w):
    ps = 0
    for i in range(h):
        if S[i][j] == "#":
            ps = 0
        else:
            ps += 1
            Gw[i][j] = ps

for i in range(h-1, -1, -1):
    ps = 0
    for j in range(w-1, -1, -1):
        if S[i][j] == "#":
            ps = 0
        else:
            ps = max(ps, Gh[i][j])
            Gh[i][j] = ps
for j in range(w-1, -1, -1):
    ps = 0
    for i in range(h-1, -1, -1):
        if S[i][j] == "#":
            ps = 0
        else:
            ps = max(ps, Gw[i][j])
            Gw[i][j] = ps
maxLight = 0
for i in range(h):
    for j in range(w):
        maxLight = max(maxLight, Gh[i][j] + Gw[i][j]-1)
print maxLight

Submission status: Runtime Error

Solution code:
import sys

readline = sys.stdin.readline

H, W = map(int, readline().split())
S = [readline().rstrip() for i in range(H)]

vert = [[0]*W for i in range(W)]
hori = [[0]*W for i in range(H)]

for y in range(H):
    for x in range(W):

        if x > 0 and S[y][x - 1] != '#':
            hori[y][x] = hori[y][x - 1]
        elif S[y][x] == '#':
            hori[y][x] = 0
        else:
            # hori
            count = 1
            while x + count < W and S[y][x + count] == '.':
                count += 1
            hori[y][x] = count

        if y > 0 and S[y - 1][x] != '#':
            vert[y][x] = vert[y - 1][x]
        elif S[y][x] == '#':
            vert[y][x] = 0
        else:
            # hori
            count = 1
            while y + count < H and S[y + count][x] == '.':
                count += 1
            vert[y][x] = count

ans = 0
for y in range(H):
    for x in range(W):
        a = hori[y][x] + vert[y][x] - 1
        ans = max(a, ans)

print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np
h,w = map(int,input().split())
s = []
s.append("_"*(w+2))
for i in range(h):
    s.append("|"+ input() + "|")
s.append("_"*(w+2))

c = np.array(s)
ansl = 0 
for i in range(h):
    for j in range(w):
        if c[1+i][1+j] == ".":
            ans = 0
            k=1
            while sc1+i+k][1+j] == ".":
                k += 1
                ans +=1
            k=1
            while c[1+i-k][1+j] == ".":
                k += 1
                ans +=1
            k=1
            while c[1+i][1+j+k] == ".":
                k += 1
                ans +=1
            k=1
            while c[1+i][1+j-k] == ".":
                k += 1
                ans +=1
            if ans > ansl:
                ansl = ans
            
print(ansl + 1)

Submission status: Runtime Error

Solution code:
line = input().split()
N = int(line[0])
M = int(line[1])
broken = []
count = 0
step = []
def check(value):
  if count < M:
    return broken[count]==value
  else:
    return False

for i in range(M):
  a = int(input())
  broken += [a]
if check(1):
  step+=[0]
  count += 1
else:
  step +=[1]
if check(2):
  step += [0]
  count += 1
else:
  step += [1+step[0]]
for j in range(2, N):
  if check(j+1):
    step += [0]
    count += 1
  else:
    step += [step[j-2]+step[j-1]]
ans = step[N-1]%(10^9+7)
print(ans)

Submission status: Runtime Error

Solution code:
inf = input().split()
H = int(inf[0])
W = int(inf[1])
sheet = [[] for i in range(H+2)]
score = [[] for i in range(H+2)]
m = 0
 
for h in range(H+2):
  if h==0 or h==H+1:
    a = [False]*(W+2)
    b = [(0,0)]*(W+2)
    sheet[h]=a
    score[h]=b
  else:
    line = input()
    a = []
    b = []
    a += [False]
    b += [(0,0)]
    for w in range(W):
      b+=[(0,0)]
      if line[w]=='.':
        a += [True]
      else:
        a += [False]
    a += [False]
    b += [(0,0)]
    sheet[h]=a
    sheet[w]=b
      
for h in range(1,H+1):
  for w in range(1,W+1):
    if sheet[h][w]:
      s = 0
      hs = 0
      ws = 0
      if sheet[h-1][w]:
        hs += score[h-1][w][0]
      else:
        i = h+1
        while sheet[i][w]:
          hs+=1
          i+=1
      if sheet[h][w-1]:
        ws += score[h][w-1][1]
      else:
        j = w+1
        while sheet[h][j]:
          ws+=1
          j+=1
      s = 1 + hs + ws
      score[h][w]=(hs, ws)
      if m < s:
        m = s
print(m)

Submission status: Runtime Error

Solution code:
inf = input().split()
H = int(inf[0])
W = int(inf[1])
dic = {}
score = {}
m = 0

for h in range(H+2):
  if h==0 or h==H+1:
    for w in range(W+2):
      dic[(h,w)] = False
      score[(h,w)] = (0,0)
  else:
    line = input()
    dic[(h,0)] = False
    dic[(h,W+1)] = False
    score[(h,0)] = (0,0)
    score[(h, w+1)] = (0,0)
    for w in range(W):
      if line[w]=='.':
        dic[(h,w+1)] = True
      else:
        dic[(h,w+1)] = False
      
for h in range(1,H+1):
  for w in range(1,W+1):
    score[(h,w)]=(0,0)
    if dic[(h,w)]:
      s = 0
      hs = 0
      ws = 0
      if dic[(h-1,w)]:
        s += score[(h-1,w)][0]
        hs += score[(h-1,w)][0]
      else:
        i = h+1
        while dic[(i,w)]:
          score[(h,w)]+=1
          i+=1
      if dic[(h, w-1)]:
        s += score[(h, w-1)][1]
        ws += score[(h,w-1)][1]
      else:
        j = w+1
        while dic[(h,j)]:
          score[(h,w)]+=1
          j+=1
      if m < s:
        m = s
print(m)

Submission status: Runtime Error

Solution code:
l = input().split()
H = int(l[0])
W = int(l[1])

S = []
for i in range(H):
    l = input().split()
    S.append(l[0])

# print(H, W, S)

# TS = []
# for i in range(W):
#     tmp = ''
#     for j in range(H):
#         tmp += S[j][i]
#     TS.append(tmp)

# print(TS)

HL = []
for i in range(H):
    l = 0
    begin = 0
    tmp = []
    for j in range(W):
        if S[i][j] == '.':
            l += 1
        else:
            tmp.extend([l]*(j - begin))
            tmp.append(0)
            begin = j + 1
            l = 0
    if begin != W:
        tmp.extend([l]*(W - begin))
    HL.append(tmp)

WL = []
for i in range(W):
    l = 0
    begin = 0
    tmp = []
    for j in range(H):
        if S[j][i] == '.':
            l += 1
        else:
            tmp.extend([l]*(j - begin))
            tmp.append(0)
            begin = j + 1
            l = 0
    if begin != W:
        tmp.extend([l]*(W - begin))
    WL.append(tmp)

max_l = 0
for i in range(H):
    for j in range(W):
        l = HL[i][j] + WL[j][i]
        max_l = max(l, max_l)
print(max_l - 1)

Submission status: Runtime Error

Solution code:
f
    
def main():
    
    h, w = [int(x) for x in input().rstrip(" ").split(" ")]
    
    from collections import defaultdict
    maze = defaultdict(str)
    for r in range(h):
        line = input().rstrip(" ")
        
        for c in range(w):
            maze[r,c] = line[c]
    
    counter_left = defaultdict(int)
    
    for r in range(h):
        
        for c in range(w):
            if maze[r,c] == "#":
                counter_left[r,c] = 0
            else:
                counter_left[r,c] = counter_left[r,c-1] + 1
    
    counter_right = defaultdict(int)
    for r in range(h):
        
        for i in range(w):
            c = (w - 1) - i
            if maze[r,c] == "#":
                counter_right[r,c] = 0
            else:
                counter_right[r,c] = counter_right[r,c+1] + 1
    
    counter_up = defaultdict(int)
    for c in range(w):
        for r in range(h):
            if maze[r,c] == "#":
                counter_up[r,c] = 0
            else:
                counter_up[r,c] = counter_up[r-1,c] + 1
            
    counter_down = defaultdict(int)
    for c in range(w):
        for i in range(h):
            r = (h - 1) - i
            if maze[r,c] == "#":
                counter_down[r,c] = 0
            else:
                counter_down[r,c] = counter_down[r+1,c] + 1
    

    best = 0
    for r in range(h):
        for c in range(w):
            score = counter_left[r,c] + counter_right[r,c] + counter_up[r,c] + counter_down[r,c] - 3
            if score > best:
                best = score
    
    print(best)
    
    
if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
h,w = (int(i) for i in input().split())
s = [input() for i in range(h)]
x,y,ans = [[0]*w for i in range(h)],[[0]*w for i in range(h)],0
for i in range(h):
    f = 0
    for j in range(w):
        if f and s[i][j]==".": num+=1
        elif f:
            for k in range(num): x[i][j-k-1] = num
            f,num = 0,0
        elif s[i][j]==".": f,num = 1,1
    if num:
        for k in range(num): x[i][j-k] = num
for i in range(w):
    f = 0
    for j in range(h):
        if f and s[j][i]==".": num+=1
        elif f:
            for k in range(num): y[j-k-1][i] = num
            f,num = 0,0
        elif s[j][i]==".": f,num = 1,1
    if num:
        for k in range(num): y[j-k][i] = num
for i in range(h):
    for j in range(w): ans = max(ans,x[i][j]+y[i][j]-1)
print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np
import pandas as pd
import sys, io
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8')

'''
h=4
w=6
x=[['#', '.', '.', '#', '.', '.'], ['.', '.', '.', '.', '.', '#'], ['.', '.', '.', '.', '#', '.'], ['#', '.', '#', '.', '.', '.']]
'''
h,w=map(int,input().split())
x1=list(input())
x=[x1]
for u in range(1,h):
	aaa=list(input())
	x.append(aaa)

l=[[0 for _ in range(w)]for _ in range(h)]
r=[[0 for _ in range(w)]for _ in range(h)]
p=[[0 for _ in range(w)]for _ in range(h)]
n=[[0 for _ in range(w)]for _ in range(h)]
count=0
num=0




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

		if(i==0):
			p[i][j]=0
		elif (x[i][j]=='#'):
			p[i][j]=0
		elif(x[i-1][j]=='#'):
			p[i][j]=0
		else:
			p[i][j]=p[i-1][j]+1

		
		if(j==0):
			r[h-1-i][w-1-j]=0
		elif(x[h-1-i][w-j-1]=='#'):
			r[h-1-i][w-1-j]=0
		elif(x[h-1-i][w-j]=='#'):
			r[h-1-i][w-1-j]=0
		else:
			r[h-1-i][w-1-j]=r[h-1-i][w-j]+1

		
		if(i==0):
			n[h-1-i][w-1-j]=0
		elif(x[h-1-i][w-j-1]=='#'):
			n[h-1-i][w-1-j]=0
		elif(x[h-i][w-1-j]=='#'):
			n[h-1-i][w-1-j]=0
		else:
			n[h-1-i][w-1-j]=n[h-i][w-1-j]+1
		

for a in range(h):
	for b in range(w):
		num=l[a][b]+r[a][b]+p[a][b]+n[a][b]+1

	
		if(count<num):
			count=num
		else:
			pass
		

print(count)

Submission status: Runtime Error

Solution code:
import numpy as np
import pandas as pd
import sys, io
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8')


h=4
w=6
x=[['#', '.', '.', '#', '.', '.'], ['.', '.', '.', '.', '.', '#'], ['.', '.', '.', '.', '#', '.'], ['#', '.', '#', '.', '.', '.']]

#h,w=map(int,input().split())
#x1=list(input())
#x=[x1]
#for u in range(1,h):
#	aaa=list(input())
#	x.append(aaa)

l=[[0 for _ in range(w)]for _ in range(h)]
r=[[0 for _ in range(w)]for _ in range(h)]
p=[[0 for _ in range(w)]for _ in range(h)]
n=[[0 for _ in range(w)]for _ in range(h)]
count=0
num=0




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

		if(i==0):
			p[i][j]=0
		elif (x[i][j]=='#'):
			p[i][j]=0
		elif(x[i-1][j]=='#'):
			p[i][j]=0
		else:
			p[i][j]=p[i-1][j]+1

		
		if(j==0):
			r[h-1-i][w-1-j]=0
		elif(x[h-1-i][w-j-1]=='#'):
			r[h-1-i][w-1-j]=0
		elif(x[h-1-i][w-j]=='#'):
			r[h-1-i][w-1-j]=0
		else:
			r[h-1-i][w-1-j]=r[h-1-i][w-j]+1

		
		if(i==0):
			n[h-1-i][w-1-j]=0
		elif(x[h-1-i][w-j-1]=='#'):
			n[h-1-i][w-1-j]=0
		elif(x[h-i][w-1-j]=='#'):
			n[h-1-i][w-1-j]=0
		else:
			n[h-1-i][w-1-j]=n[h-i][w-1-j]+1
		
		'''
		num=l[i][j]+r[h-1-i][w-1-j]+p[i][j]+n[h-1-i][w-1-j]-3
		print(num)
		if(count<num):
			count=num
		else:
			pass
		'''
'''		
for i in range(h-1,0):
	for j in range(w-1,0):
		if(x[i][j]=='#'):
			r[i][j]=0
		elif(j==w-1):
			r[i][j]=0
		else:
			r[i][j]=r[i][j+1]+1

		if(x[i][j]=='#'):
			n[i][j]=0
		if(i==h-1):
			n[i][j]=0
		else:
			n[i][j]=n[i+1][j]+1
		
'''

for a in range(h):
	for b in range(w):
		num=l[a][b]+r[a][b]+p[a][b]+n[a][b]+1
		#print(l[a][b],r[a][b],p[a][b],n[a][b],num)
	
		if(count<num):
			count=num
		else:
			pass
		#print(count)

print(count)

Submission status: Runtime Error

Solution code:
import sys
import math 
ni = lambda: int(ns())
import numpy as np
na = lambda: list(map(int, input().split()))
ns = lambda: input()

h,w  = na()
grid = [input().strip() for i in range(h)]
#print(grid)

T = [[0]*w for i in range(h)]
Y = [[0]*w for i in range(h)]

for i in range(h):
    count=0
    for j in range(w):
        if(grid[i][j]=="#"):
            count=0
        else:
            count+=1
            #print(i,j)
            T[i][j]=count

for i in range(h):
    for j in range(w-2,-1,-1):
        if grid[i][j] == "#":
            T[i][j] = 0
        else:
            T[i][j] = max(T[i][j],T[i][j+1])

for j in range(w):
    count=0
    for i in range(h):
        if(grid[i][j]=="#"):
            count=0
        else:
            count+=1
            Y[i][j]=count

for j in range(w):
    for i in range(h-2,-1,-1):
        if grid[i][j] == "#":
            Y[i][j] = 0
        else:
            Y[i][j] = max(Y[i][j],Y[i+1][j])

ANS = -1
for i in range(h):
    for j in range(w):
        ANS = max(ANS, Y[i][j] + T[i][j] - 1)
#print(T)
#print(Y)
print(ANS)

Submission status: Runtime Error

Solution code:
from collections import namedtuple
from itertools import chain

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

class Node():
    __slots__ = ['good', 'left', 'up', 'right', 'down']
    def __init__(self, good, left, up, right, down):
        self.good = good
        self.left = left
        self.up = up
        self.right = right
        self.down = down
    def neighbours(self):
        return self.left + self.up + self.right + self.down + int(self.good)
    def __repr__(self):
        return "{} {} {} {} {}".format(self.good, self.left, self.up, self.right, self.down)

nodes = [ [ None for _ in range(w) ] for _ in range(h) ]
lastUp = [0 for _ in range(w)]
lastLeft = 0
for i in range(h):
    lastLeft = 0
    for j,c in enumerate(input()):
        good = c == '.'
        left = 0
        up = 0
        right = w - j - 1
        down = h - i - 1
        if good:
            if j > 0:
                l = nodes[i][j - 1]
                left = l.left + int(l.good)
            if i > 0:
                u = nodes[i - 1][j]
                up = u.up + int(u.good)
        else:
            right = 0
            down = 0
            for k in range(lastLeft, j):
                nodes[i][k].right = j - k - 1
                steps += 1
            for k in range(lastUp[j], i):
                nodes[k][j].down = i - k - 1
                steps += 1
            lastLeft = j + 1
            lastUp[j] = i + 1
        nodes[i][j] = Node(good, left, up, right, down)

print(max(map(lambda x: x.neighbours(), chain(*nodes))))

Submission status: Runtime Error

Solution code:
from collections import namedtuple

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

class Node():
    __slots__ = ['good', 'left', 'up', 'right', 'down']
    def __init__(self, good, left, up, right, down):
        self.good = good
        self.left = left
        self.up = up
        self.right = right
        self.down = down
    def neighbours(self):
        return self.left + self.up + self.right + self.down + 1
    def __repr__(self):
        return f"{self.good} {self.left} {self.up} {self.right} {self.down}"

nodes = {}
downStreak = [0 for i in range(w)]
for i in range(h):
    s = input()
    rightStreak = 0
    for j,c in enumerate(s):
        n = Node(c == '.', 0, 0, 0, 0)
        if n.good:
            rightStreak += 1
            downStreak[j] += 1

            if j > 0:
                l = nodes[(i, j - 1)]
                n.left = l.left + int(l.good)
                if l.good:
                    for k in reversed(range(j - rightStreak + 1, j)):
                        nodes[(i, k)].right += 1
            if i > 0:
                u = nodes[(i - 1, j)]
                n.up = u.up + int(u.good)
                if u.good:
                    for k in reversed(range(i - downStreak[j] + 1, i)):
                        nodes[(k, j)].down += 1
        else:
            rightStreak = 0
            downStreak[j] = 0
        nodes[(i, j)] = n

# print('\n'.join(map(str, nodes.items())))
print(max(map(lambda x: x.neighbours(), nodes.values())))