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:
import sys
sys.setrecursionlimit(2147483647)
INF=float('inf')

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

yoko=[[0]*w for _ in range(h)]
tate=[[0]*w for _ in range(h)]

def yoko_check(y,x,cnt):
    global yoko,s
    if x==w-1:
        yoko[y][x]=cnt
        return cnt
    else:
        if s[y][x+1]=="#":
            yoko[y][x]=cnt
            return cnt
        else:
            yoko[y][x]=yoko_check(y,x+1,cnt+1)
            return yoko[y][x]


def tate_check(y,x,cnt):
    global tate,s
    if y==h-1:
        tate[y][x]=cnt
        return cnt
    else:
        if s[y+1][x]=="#":
            tate[y][x]=cnt
            return cnt
        else:
            tate[y][x]=tate_check(y+1,x,cnt+1)
            return tate[y][x]


for y in range(h):
    for x in range(w):
        if yoko[y][x]==0 and s[y][x]==".":
            yoko_check(y,x,1)
        if tate[y][x]==0 and s[y][x]==".":
            tate_check(y,x,1)

result=0
for y in range(h):
    for x in range(w):
        if s[y][x]==".":
            result=max(result,tate[y][x]+yoko[y][x]-1)  

print(result)

Submission status: Time Limit Exceeded

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

Light = [[[0, 0]for _ in range(W)] for __ in range(H)]


for i in range(H):
    for j in range(W):
        if maze[i][j] == '#':
            continue
        if Light[i][j][0] == 0:
            num = 0
            while True:
                num += 1
                if i + num >= H:
                    break
                if maze[i+num][j] == '#':
                    break
            for k in range(num):
                Light[i+k][j][0] = num


        if Light[i][j][1] == 0:
            num = 0
            while True:
                num += 1
                if j + num >= W:
                    break
                if maze[i][j + num] == '#':
                    break
            for k in range(num):
                Light[i][j+k][1] = num

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

Submission status: Time Limit Exceeded

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

s = [[x for x in input()]for i in range(h)]
t = [[0 for i in range(w)]for j in range(h)]

for i in range(h):
    c = 1
    for j in range(w):
        if s[i][j] == '#':
            c = 1
        else:
            t[i][j] += c
            c += 1


for i in range(h):
    c = 0
    for j in range(w-1, -1, -1):
        if s[i][j] == '#':
            c = 0
        else:
            t[i][j] += c
            c += 1

for j in range(w):
    c = 1
    for i in range(h):
        if s[i][j] == '#':
            c = 1
        else:
            t[i][j] += c
            c += 1

for j in range(w):
    c = 0
    for i in range(h-1, -1, -1):
        if s[i][j] == '#':
            c = 0
        else:
            t[i][j] += c
            c += 1
# print(t)
ans = 0
for i in range(h):
    ans = max(max(t[i]), ans)
print(ans-1)

Submission status: Time Limit Exceeded

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

H,W = (int(x) for x in input().split())
S = [list(input()) for _ in range(H)]
mem = [[[0,0] for _ in range(W)] for _ in range(H)]
ans = 0
for i in range(H):
    for j in range(W):
        if S[i][j] == '.':
            h = mem[i][j][0]
            if h == 0:
                stopped = False
                for k in range(W-j-1):
                    if S[i][j+k+1] == '#':
                        for l in range(k+1):
                            mem[i][j+l][0] = k+1
                        stopped = True
                        break
                if stopped == False:
                    for l in range(W-j):
                        mem[i][j+l][0] = W-j
                h = mem[i][j][0]
            v = mem[i][j][1]
            if v == 0:
                stopped = False
                for k in range(H-i-1):
                    if S[i+k+1][j] == '#':
                        for l in range(k+1):
                            mem[i+l][j][1] = k+1
                        stopped = True
                        break
                if stopped == False:
                    for l in range(H-i):
                        mem[i+l][j][1] = H-i
                v = mem[i][j][1]
            ans = max(ans,h+v-1)
print(ans)

Submission status: Time Limit Exceeded

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

from itertools import chain
H,W = (int(x) for x in input().split())
S = [list(input()) for _ in range(H)]
mem = [[[0,0] for _ in range(W)] for _ in range(H)]
ans = [[0] * W for _ in range(H)]
for i in range(H):
    for j in range(W):
        if S[i][j] == '.':
            h = mem[i][j][0]
            if h == 0:
                stopped = False
                for k in range(W-j-1):
                    if S[i][j+k+1] == '#':
                        for l in range(k+1):
                            mem[i][j+l][0] = k+1
                        stopped = True
                        break
                if stopped == False:
                    for l in range(W-j):
                        mem[i][j+l][0] = W-j
                h = mem[i][j][0]
            v = mem[i][j][1]
            if v == 0:
                stopped = False
                for k in range(H-i-1):
                    if S[i+k+1][j] == '#':
                        for l in range(k+1):
                            mem[i+l][j][1] = k+1
                        stopped = True
                        break
                if stopped == False:
                    for l in range(H-i):
                        mem[i+l][j][1] = H-i
                v = mem[i][j][1]
            ans[i][j] = h + v - 1
print(max(chain(*ans)))

Submission status: Time Limit Exceeded

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

from itertools import chain
H,W = (int(x) for x in input().split())
S = [list(input()) for _ in range(H)]
mem = [[[0,0] for _ in range(W)] for _ in range(H)]
ans = [[0] * W for _ in range(H)]
for i in range(H):
    for j in range(W):
        if S[i][j] == '.':
            if mem[i][j][0]:
                h = mem[i][j][0]
            else:
                stopped = False
                for k in range(W-j-1):
                    if S[i][j+k+1] == '#':
                        for l in range(k+1):
                            mem[i][j+l][0] = k+1
                        stopped = True
                        break
                if stopped == False:
                    for l in range(W-j):
                        mem[i][j+l][0] = W-j
                h = mem[i][j][0]
            if mem[i][j][1]:
                v = mem[i][j][1]
            else:
                stopped = False
                for k in range(H-i-1):
                    if S[i+k+1][j] == '#':
                        for l in range(k+1):
                            mem[i+l][j][1] = k+1
                        stopped = True
                        break
                if stopped == False:
                    for l in range(H-i):
                        mem[i+l][j][1] = H-i
                v = mem[i][j][1]
            ans[i][j] = h + v - 1
print(max(chain(*ans)))

Submission status: Time Limit Exceeded

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

H,W = (int(x) for x in input().split())
S = [list(input()) for _ in range(H)]
mem = [[[0,0] for _ in range(W)] for _ in range(H)]
ans = [[0] * W for _ in range(H)]
for i in range(H):
    for j in range(W):
        if S[i][j] == '.':
            if mem[i][j][0]:
                h = mem[i][j][0]
            else:
                stopped = False
                for k in range(W-j-1):
                    if S[i][j+k+1] == '#':
                        for l in range(k+1):
                            mem[i][j+l][0] = k+1
                        stopped = True
                        break
                if stopped == False:
                    for l in range(W-j):
                        mem[i][j+l][0] = W-j
                h = mem[i][j][0]
            if mem[i][j][1]:
                v = mem[i][j][1]
            else:
                stopped = False
                for k in range(H-i-1):
                    if S[i+k+1][j] == '#':
                        for l in range(k+1):
                            mem[i+l][j][1] = k+1
                        stopped = True
                        break
                if stopped == False:
                    for l in range(H-i):
                        mem[i+l][j][1] = H-i
                v = mem[i][j][1]
            ans[i][j] = h + v - 1
print(max(sum(ans,[])))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

def ABC129D(s):
    h = len(s)
    w = len(s[0])
    m = np.reshape(np.repeat('#', (h+2)*(w+2)), (h+2, w+2))
    for i in range(h):
        m[i+1, 1:w+1] = list(s[i])
    ans = 0
    for i in range(1, h+1):
        #print("i =", i); i = 2
        begin = 1
        while True:
            while begin < w+1 and m[i, begin] == "#":
                begin += 1
            end = begin + 1
            while end < w+1 and m[i, end] == ".":
                end += 1
            horizontal = end - begin
            vertical = 0
            for j in range(begin, end):
                up = i
                while m[up, j] == ".":
                    up -= 1
                down = i + 1
                while m[down, j] == ".":
                    down += 1
                vertical = max(vertical, down - up - 1)
            ans = max(ans, horizontal + vertical)
            begin = end
            if begin >= w:
                break
    print(ans-1)

h, w = map(int, input().split())
s = [0] * h
for i in range(h):
    s[i] = input()
# s = ['#..#..', '.....#', '....#.', '#.#...']
ABC129D(s)

Submission status: Time Limit Exceeded

Solution code:
# import itertools
# import pprint
# import copy
# from collections import deque

h,w   = map(int,input().split())
mp    = list(list(input()) for i in range(h))
scx   = [[0 for _ in range(w)] for _ in range(h)]
scy   = [[0 for _ in range(w)] for _ in range(h)]
donex = [[0 for _ in range(w)] for _ in range(h)]
doney = [[0 for _ in range(w)] for _ in range(h)]
sc    = 0
ans   = 0

for y in range(h):
  for x in range(w):
    if mp[y][x]=='#':
      scx[y][x]==0
    elif donex[y][x]==1:
      continue
    else:
      l = 1
      while(x+l<w):
        if mp[y][x+l]=='#':
          break
        l += 1
      for i in range(l):
        scx[y][x+i] = l
        donex[y][x+i] = 1

for y in range(h):
  for x in range(w):
    if mp[y][x]=='#':
      scy[y][x]==0
    elif doney[y][x]==1:
      continue
    else:
      l = 1
      while(y+l<h):
        if mp[y+l][x]=='#':
          break
        l += 1
      for i in range(l):
        scy[y+i][x] = l
        doney[y+i][x] = 1

for y in range(h):
  for x in range(w):
    ans = max(ans, (scy[y][x] + scx[y][x] - 1))

print(ans)

Submission status: Time Limit Exceeded

Solution code:
H,W=map(int, input().split()) 
S=[[0 for _ in range(W+2)] for _ in range(H+2)]
for i in range(H):
  S[i+1]= ["#"] + list(input()) + ["#"]
for j in range(W+2):
  S[0][j]="#"
  S[-1][j]="#"
  
t=[[-1 for _ in range(W)] for _ in range(H)]
y=[[-1 for _ in range(W)] for _ in range(H)]

for i in range(H):
  for j in range(W):
    if S[i+1][j+1]==".":
      if t[i][j]==-1:
        k=1
        while True:
          if S[i+k+1][j+1]==".":
            k +=1
          else:
            break
        for l in range(k):
          t[i+l][j]=k       
      if y[i][j]==-1:
        m=1
        while True:
          if S[i+1][j+1+m]==".":
            m +=1
          else:
            break
        for n in range(m):
          y[i][j+n]=m       

maxi=0          
for i in range(H):
  for j in range(W):
    maxi=max(maxi, t[i][j]+y[i][j])
print(maxi-1)

Submission status: Time Limit Exceeded

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

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

for i in range(h):
    count=1
    for j in range(w):
        if(s[i][j]=='.'):
            left[i][j]=count
            count+=1
        else:
            left[i][j]=0
            count=1

for i in range(h):
    count=1
    for j in range(w-1,-1,-1):
        if(s[i][j]=='.'):
            right[i][j]=count
            count+=1
        else:
            right[i][j]=0
            count=1

for j in range(w):
    count=1
    for i in range(h):
        if(s[i][j]=='.'):
            up[i][j]=count
            count+=1
        else:
            up[i][j]=0
            count=1

ans=0
for j in range(w):
    count=1
    for i in range(h-1,-1,-1):
        if(s[i][j]=='.'):
            down[i][j]=count
            count+=1
        else:
            down[i][j]=0
            count=1

        ans=max(ans,left[i][j]+right[i][j]+up[i][j]+down[i][j]-3)

print(ans)

Submission status: Time Limit Exceeded

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

MW = [[0]*w for _ in range(h)]
MH = [[0]*w for _ in range(h)]


for i in range(h):
  l = 0
  c = 0
  for r in range(w):    
    if F[i][r] == '#':
      for k in range(l,r):
        MW[i][k] = c
      l = r+1
      c = 0      
    else:
      c += 1
  for k in range(l,r+1):
    MW[i][k] = c  
    
for i in range(w):
  u = 0
  c = 0
  for b in range(h):    
    if F[b][i] == '#':
      for k in range(u,b):
        MH[k][i] = c
      u = b+1
      c = 0      
    else:
      c += 1
  for k in range(u,b+1):
    MH[k][i] = c      
    
ans = 0    
for i in range(h):
  for j in range(w):
    tmp = 0
    if F[i][j] != '#':
      tmp = MH[i][j]+MW[i][j] -1 
    ans = max(ans,tmp)
    
print(ans)

Submission status: Time Limit Exceeded

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

h,w=map(int,input().split())
S=[["#"]+list(input())+["#"] for _ in range(h)]
S.insert(0,["#"]*(w+2))
S.append(["#"]*(w+2))

C=[[[0]*4 for _ in range(w+2)] for _ in range(h+2)]
for i in range(1,h+1):
    for n, flag in enumerate((1, -1)):
        for j in range(1,w+1)[::flag]:
            if S[i][j]!="#":C[i][j][n] +=C[i][j-flag][n]+1
for i in range(1,w+1):
    for n, flag in enumerate((1, -1)):
        for j in range(1,h+1)[::flag]:
            if S[j][i]!="#":C[j][i][n+2] +=C[j-flag][i][n+2]+1

print(max([sum(C[i][j])-3 for i in range(1,h+1) for j in range(1,w+1)]))

Submission status: Time Limit Exceeded

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

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

for i in range(W):  #下
    for j in range(H):
        if j==0 and S[j][i]=='.':
            DURL[j][i][0]=1
        elif S[j][i]=='.':
            DURL[j][i][0]=DURL[j-1][i][0]+1
for i in range(W):  #上
    for j in range(H)[::-1]:
        if j==H-1 and S[j][i]=='.':
            DURL[j][i][1]=1
        elif S[j][i]=='.':
            DURL[j][i][1]=DURL[j+1][i][1]+1

for i in range(H):  #右
    for j in range(W):
        if j==0 and S[i][j]=='.':
            DURL[i][j][2]=1
        elif S[i][j]=='.':
            DURL[i][j][2]=DURL[i][j-1][2]+1
for i in range(H):  #左
    for j in range(W)[::-1]:
        if j==W-1 and S[i][j]=='.':
            DURL[i][j][3]=1
        elif S[i][j]=='.':
            DURL[i][j][3]=DURL[i][j+1][3]+1

#print(DURL)

ans=0
for i in range(H):
    for j in range(W):
        cnt=sum(DURL[i][j])-3
        ans=max(ans,cnt)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import numpy as np 

def main():
    H, W = map(int , readline().split())
    A = np.zeros((H+1, W+1), np.int64)
    A[:H, :] = (np.frombuffer(read(H*(W+1)), 'B') == ord('.')).reshape((H, W+1))
    for j in range(H):
        prev = 0
        start = 0
        for i in range(W+1):
            if A[j, i] > 0:
                if prev == 0:
                    start = i 
                    prev = 1
            else:
                if prev == 1:
                    n = i - start
                    for k in range(start, i):
                        A[j, k] = n
                    prev = 0 
    

    for i in range(W):
        prev = 0
        start = 0
        for j in range(H+1):
            if A[j, i] > 0:
                if prev == 0:
                    start = j
                    prev = 1
            else:
                if prev == 1:
                    n = j - start - 1
                    for k in range(start, j):
                        A[k, i] += n
                    prev = 0

    print(A.max())
if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import numpy as np 
def main():
    H, W = map(int , readline().split())
    A = []
    for i in range(H):
        A.append([1 if i == ord('.') else 0 for i in readline()])
    A.append([0 for _ in range(W+1)])

    for j in range(H):
        prev = 0
        start = 0
        for i in range(W+1):
            if A[j][i] > 0:
                if prev == 0:
                    start = i 
                    prev = 1
            else:
                if prev == 1:
                    n = i - start
                    for k in range(start, i):
                        A[j][k] = n
                    prev = 0 
    
    ans = 0
    for i in range(W):
        prev = 0
        start = 0
        for j in range(H+1):
            if A[j][i] > 0:
                if prev == 0:
                    start = j
                    prev = 1
            else:
                if prev == 1:
                    n = j - start - 1
                    for k in range(start, j):
                        A[k][i]+= n
                        ans = max(ans, A[k][i])
                    prev = 0
    print(ans)
if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import numpy as np 
def main():
    H, W = map(int , readline().split())
    A = np.array([1 if i == ord('.') else 0 for i in read()], np.int16).reshape(H, W+1)
    A = np.vstack((A, np.zeros(W+1, np.int16)))

    for j in range(H):
        prev = 0
        start = 0
        for i in range(W+1):
            if A[j, i] > 0:
                if prev == 0:
                    start = i 
                    prev = 1
            else:
                if prev == 1:
                    n = i - start
                    for k in range(start, i):
                        A[j, k] = n
                    prev = 0 
    

    for i in range(W):
        prev = 0
        start = 0
        for j in range(H+1):
            if A[j, i] > 0:
                if prev == 0:
                    start = j
                    prev = 1
            else:
                if prev == 1:
                    n = j - start - 1
                    for k in range(start, j):
                        A[k, i] += n
                    prev = 0

    print(A.max())
if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import numpy as np 
def main():
    H, W = map(int , readline().split())
    A = np.array([1 if i == ord('.') else 0 for i in read()], np.int16).reshape(H, W+1)
    A = np.vstack((A, np.zeros(W+1, np.int16)))
    row = np.zeros((H+1, W+1), np.int16)
    clumn = np.copy(row)

    for j in range(H):
        prev = 0
        start = 0
        for i in range(W+1):
            if A[j, i] == 1:
                if prev == 0:
                    start = i 
                    prev = 1
            else:
                if prev == 1:
                    n = i - start
                    for k in range(start, i):
                        row[j, k] = n
                    prev = 0 
    

    for i in range(W):
        prev = 0
        start = 0
        for j in range(H+1):
            if A[j, i] == 1:
                if prev == 0:
                    start = j
                    prev = 1
            else:
                if prev == 1:
                    n = j - start
                    for k in range(start, j):
                        clumn[k, i] = n
                    prev = 0

    print((row+clumn).max()-1)
if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines



def main():
    H, W = map(int, readline().split())
    g = []
    for _ in range(H):
        s = readline().rstrip().decode()
        g.append(s)

    def rowBeam(si, sj):
        cnt1 = 0
        cnt2 = 0
        for dj in range(W):
            x = sj+dj
            if x>=W:
                break
            if g[si][x] == '#':
                break
            cnt1 += 1
        for dj in range(W):
            x = sj-dj
            if x<0:
                break
            if g[si][x] == '#':
                break
            cnt2 += 1
        return cnt1+cnt2-1


    def clumnBeam(si, sj):
        cnt1 = 0
        cnt2 = 0
        for di in range(H):
            x = si+di
            if x>=H:
                break
            if g[x][sj] == '#':
                break
            cnt1 += 1
        for di in range(H):
            x = si-di
            if x<0:
                break
            if g[x][sj] == '#':
                break
            cnt2 += 1
        return cnt1+cnt2-1

    ans = 0
    for si in range(H):
        for sj in range(W):
            if g[si][sj] == '#':
                continue
            tmp = rowBeam(si, sj) + clumnBeam(si, sj)
            ans = max(ans, tmp)
    print(ans-1)
if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
#ABC 129 D
H,W=map(int,input().split(' '))
s=[0]*H
for i in range(H):
    s[i]=input()

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

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

Submission status: Time Limit Exceeded

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines



def main():
    H, W = map(int, readline().split())
    g = []
    for _ in range(H):
        s = readline().rstrip().decode()
        g.append(s)

    def rowBeam(si, sj):
        cnt1 = 0
        cnt2 = 0
        for dj in range(W):
            x = sj+dj
            if x>=W:
                break
            if g[si][x] == '#':
                break
            cnt1 += 1
        for dj in range(W):
            x = sj-dj
            if x<0:
                break
            if g[si][x] == '#':
                break
            cnt2 += 1
        return cnt1+cnt2-1


    def clumnBeam(si, sj):
        cnt1 = 0
        cnt2 = 0
        for di in range(H):
            x = si+di
            if x>=H:
                break
            if g[x][sj] == '#':
                break
            cnt1 += 1
        for di in range(H):
            x = si-di
            if x<0:
                break
            if g[x][sj] == '#':
                break
            cnt2 += 1
        return cnt1+cnt2-1

    ans = 0
    for si in range(H):
        for sj in range(W):
            if g[si][sj] == '#':
                continue
            tmp = rowBeam(si, sj) + clumnBeam(si, sj)
            ans = max(ans, tmp)
    print(ans-1)
if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

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

grow = np.zeros((H, W), np.int16)

for i in range(H):
    j = 0
    while j < W:
        if field[i][j] == '.':
            counter = 0
            while j+counter < W and field[i][j+counter] == '.':
                counter += 1
            grow[i, j:j+counter] = counter
            j += counter
        j += 1

for j in range(W):
    i = 0
    while i < H:
        if field[i][j] == '.':
            counter = 0
            while i+counter < H and field[i+counter][j] == '.':
                counter += 1
            grow[i:i+counter, j] += counter
            i += counter
        i += 1

print(np.amax(grow) - 1)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

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

grow_row = np.empty((H, W), np.int16)
grow_col = np.empty((H, W), np.int16)

for i in range(H):
    j = 0
    while j < W:
        if field[i][j] == '#':
            grow_row[i, j] = -1
            j += 1
        else:
            counter = 0
            while j+counter < W and field[i][j+counter] == '.':
                counter += 1
            grow_row[i, j:j+counter] = counter
            j += counter

for j in range(W):
    i = 0
    while i < H:
        if field[i][j] == '#':
            grow_col[i, j] = -1
            i += 1
        else:
            counter = 0
            while i+counter < H and field[i+counter][j] == '.':
                counter += 1
            grow_col[i:i+counter, j] = counter
            i += counter

print(np.amax(grow_col + grow_row) - 1)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

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

grow_row = np.empty((H, W), np.int64)
grow_col = np.empty((H, W), np.int64)

for i in range(H):
    j = 0
    while j < W:
        if field[i][j] == '#':
            grow_row[i, j] = -1
            j += 1
        else:
            counter = 0
            while j+counter < W and field[i][j+counter] == '.':
                counter += 1
            grow_row[i, j:j+counter] = counter
            j += counter

for j in range(W):
    i = 0
    while i < H:
        if field[i][j] == '#':
            grow_col[i, j] = -1
            i += 1
        else:
            counter = 0
            while i+counter < H and field[i+counter][j] == '.':
                counter += 1
            grow_col[i:i+counter, j] = counter
            i += counter

print(np.amax(grow_col + grow_row) - 1)

Submission status: Time Limit Exceeded

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

A = [[0]*(W) for i in range(H)]
B = [[0]*(W) for i in range(H)]

for i in range(H):
    a = 0
    f = 0
    t = 0
    for j in range(W):
        if data[i][j] == '.' and j < W-1:
            a += 1
            t += 1
        elif data[i][j] == '#':
            for k in range(f,t):
                A[i][k] = a
            t = j+1
            f = j+1
            a = 0
        else:
            for k in range(f,t+1):
                A[i][k] = a+1
for j in range(W):
    b = 0
    f = 0
    t = 0
    for i in range(H):
        if data[i][j] == '.' and i < H-1:
            b += 1
            t += 1
        elif data[i][j] == '#':
            for k in range(f,t):
                B[k][j] = b
            t = i+1
            f = i+1
            b = 0
        else:
            for k in range(f,t+1):
                B[k][j] = b+1
ans = 0
for i in range(H):
    for j in range(W):
        ans = max(ans,A[i][j]+B[i][j])
print(ans-1)

Submission status: Time Limit Exceeded

Solution code:
import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()

def resolve():

    H,W=map(int,input().split())
    grid=[[_ for _ in input()] for _ in range(H)]
    ans=0
    for h in range(H):
        for w in range(W):
            if grid[h][w]=='.':
                cnt=1
                i=1
                while True:
                    if h+i<H and grid[h+i][w]=='.':
                        cnt+=1
                        i+=1
                    else:
                        break
                i=1
                while True:
                    if w+i<W and grid[h][w+i]=='.':
                        cnt+=1
                        i+=1
                    else:
                        break
                i=1
                while True:
                    if h-i>=0 and grid[h-i][w]=='.':
                        cnt+=1
                        i+=1
                    else:
                        break
                i=1
                while True:
                    if w-i >=0 and grid[h][w-i]=='.':
                        cnt+=1
                        i+=1
                    else:
                        break
                ans=max(ans,cnt)
    print(ans)



resolve()