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:
def slove():
    import sys
    input = sys.stdin.readline
    h, w = list(map(int, input().rstrip('\n').split()))
    s = [str(input().rstrip('\n')) for _ in range(h)]
    L = [[0] * w for _ in range(h)]
    R = [[0] * w for _ in range(h)]
    U = [[0] * w for _ in range(h)]
    D = [[0] * w for _ in range(h)]
    for i in range(h):
        for j in range(w):
            if s[i][j] == "#":
                L[i][j] = 0
            else:
                if i == 0:
                    L[i][j] = 1
                else:
                    L[i][j] = L[i - 1][j] + 1
            if s[-i-1][j] == "#":
                R[-i-1][j] = 0
            else:
                if i == 0:
                    R[-i-1][j] = 1
                else:
                    R[-i-1][j] = R[-i][j] + 1
            if s[i][j] == "#":
                U[i][j][2] = 0
            else:
                if j == 0:
                    U[i][j] = 1
                else:
                    U[i][j] = U[i][j-1] + 1
            if s[i][-j-1] == "#":
                D[i][-j-1] = 0
            else:
                if j == 0:
                    D[i][-j-1] = 1
                else:
                    D[i][-j-1] = D[i][-j] + 1
    mn = 0
    for i in range(h):
        for j in range(w):
            mn = max(mn, U[i][j] + D[i][j] + L[i][j] + R[i][j] - 3)
    print(mn)


if __name__ == '__main__':
    slove()

Submission status: Runtime Error

Solution code:
def slove():
    import sys
    input = sys.stdin.readline
    h, w = list(map(int, input().rstrip('\n').split()))
    s = [str(input().rstrip('\n')) for _ in range(h)]
    a = [[[0] * 4 for _ in range(w)] for _ in range(h)]
    for i in range(h):
        for j in range(w):
            if s[i][j] == "#":
                a[i][j][0] = 0
            else:
                if i == 0:
                    a[i][j][0] = 1
                else:
                    a[i][j][0] = a[i - 1][j][0] + 1

            if s[-i-1][j] == "#":
                a[-i-1][j][1] = 0
            else:
                if i == 0:
                    a[-i-1][j][1] = 1
                else:
                    a[-i-1][j][1] = a[-i][j][1] + 1

            if s[i][j] == "#":
                a[i][j][2] = 0
            else:
                if j == 0:
                    a[i][j][2] = 1
                else:
                    a[i][j][2] = a[i][j-1][2] + 1

            if s[i][-j-1] == "#":
                a[i][-j-1][3] = 0
            else:
                if j == 0:
                    a[i][-j-1][3] = 1
                else:
                    a[i][-j-1][
            mn = max(mn, sum(a[i][j]) - 3)
    print(mn)


if __name__ == '__main__':
    slove()

Submission status: Runtime Error

Solution code:
h,w = map(int,input().split(" "))
s = [[0 for i in range(w)] for j in range(h)]
for i in range(h):
    tmp = list(input())
    for j in range(w):
        s[i][j] = tmp[j]
dp2 = [[-1 for i in range(w)] for j in range(h)]
dp3 = [[-1 for i in range(w)] for j in range(h)]
dp4 = [[-1 for i in range(w)] for j in range(h)]
dp5 = [[-1 for i in range(w)] for j in range(h)]
dp=[dp2,dp3,dp4,dp5]

def search2(array,x,y,i,j,dp):
            if i>=0 and i<=x-1 and j>=0 and j<=y-1 and array[i][j] != "#":
                if dp[0][i][j] == -1:
                    dp[0][i][j] = 1+search2(array,x,y,i-1,j,dp)
                    return dp[0][i][j]
                else:
                    return dp[0][i][j]
            elif i>=0 and i<=x-1 and j>=0 and j<=y-1:
                dp[0][i][j] = 0
            return 0

def search3(array,x,y,i,j,dp):
            if i>=0 and i<=x-1 and j>=0 and j<=y-1 and array[i][j] != "#":
                 if dp[1][i][j] == -1:
                    dp[1][i][j] = 1+search3(array,x,y,i+1,j,dp)
                    return dp[1][i][j]
                 else:
                    return dp[1][i][j]
            elif i>=0 and i<=x-1 and j>=0 and j<=y-1:
                dp[1][i][j] = 0
            return 0

def search4(array,x,y,i,j,dp):
            if i>=0 and i<=x-1 and j>=0 and j<=y-1 and array[i][j] != "#":
                if dp[2][i][j] == -1:
                    dp[2][i][j] = 1+search4(array,x,y,i,j-1,dp)
                    return dp[2][i][j]
                else:
                    return dp[2][i][j]
            elif i>=0 and i<=x-1 and j>=0 and j<=y-1:
                dp[2][i][j] = 0
            return 0

def search5(array,x,y,i,j,dp):
            if i>=0 and i<=x-1 and j>=0 and j<=y-1 and array[i][j] != "#":
                if dp[3][i][j] == -1:
                    dp[3][i][j] = 1+search5(array,x,y,i,j+1,dp)
                    return dp[3][i][j]
                else:
                    return  dp[3][i][j]
            elif i>=0 and i<=x-1 and j>=0 and j<=y-1:
                dp[3][i][j] = 0
            return 0

            
max = 1
for i in range(h):
    a = 0
    for j in range(w):
        a = search2(s,h,w,i,j,dp) + search3(s,h,w,i,j,dp)+ search4(s,h,w,i,j,dp) + search5(s,h,w,i,j,dp)
        if a-3 > max:
            max = a-3

print(max)

Submission status: Runtime Error

Solution code:
h,w = map(int,input().split(" "))
s = [[0 for i in range(w)] for j in range(h)]
for i in range(h):
    tmp = list(input())
    for j in range(w):
        s[i][j] = tmp[j]
dp2 = [[-1 for i in range(w)] for j in range(h)]
dp3 = [[-1 for i in range(w)] for j in range(h)]
dp4 = [[-1 for i in range(w)] for j in range(h)]
dp5 = [[-1 for i in range(w)] for j in range(h)]
dp=[dp2,dp3,dp4,dp5]
def search(array,x,y,i,j,dp):
            if i>=0 and i<=x-1 and j>=0 and j<=y-1 and array[i][j] != "#":
                return -3+search2(array,x,y,i,j,dp)+search3(array,x,y,i,j,dp)+search4(array,x,y,i,j,dp)+search5(array,x,y,i,j,dp)
def search2(array,x,y,i,j,dp):
            if i>=0 and i<=x-1 and j>=0 and j<=y-1 and array[i][j] != "#":
                if dp[0][i][j] == -1:
                    dp[0][i][j] = 1+search2(array,x,y,i-1,j,dp)
                    return dp[0][i][j]
                else:
                    return dp[0][i][j]
            elif i>=0 and i<=x-1 and j>=0 and j<=y-1:
                dp[0][i][j] = 0
            return 0

def search3(array,x,y,i,j,dp):
            if i>=0 and i<=x-1 and j>=0 and j<=y-1 and array[i][j] != "#":
                 if dp[1][i][j] == -1:
                    dp[1][i][j] = 1+search3(array,x,y,i+1,j,dp)
                    return dp[1][i][j]
                 else:
                    return dp[1][i][j]
            elif i>=0 and i<=x-1 and j>=0 and j<=y-1:
                dp[1][i][j] = 0
            return 0

def search4(array,x,y,i,j,dp):
            if i>=0 and i<=x-1 and j>=0 and j<=y-1 and array[i][j] != "#":
                if dp[2][i][j] == -1:
                    dp[2][i][j] = 1+search4(array,x,y,i,j-1,dp)
                    return dp[2][i][j]
                else:
                    return dp[2][i][j]
            elif i>=0 and i<=x-1 and j>=0 and j<=y-1:
                dp[2][i][j] = 0
            return 0

def search5(array,x,y,i,j,dp):
            if i>=0 and i<=x-1 and j>=0 and j<=y-1 and array[i][j] != "#":
                if dp[3][i][j] == -1:
                    dp[3][i][j] = 1+search5(array,x,y,i,j+1,dp)
                    return dp[3][i][j]
                else:
                    return  dp[3][i][j]
            elif i>=0 and i<=x-1 and j>=0 and j<=y-1:
                dp[3][i][j] = 0
            return 0

            
max = 1
for i in range(h):
    for j in range(w):
        search2(s,h,w,i,j,dp)
        search3(s,h,w,i,j,dp)
        search4(s,h,w,i,j,dp)
        search5(s,h,w,i,j,dp)
for i in range(h):
    for j in range(w):
        a = 0
        for k in range(len(dp)):
            a += dp[k][i][j]
            if a-3 > max:
                max = a-3

print(max)

Submission status: Runtime Error

Solution code:
h,w = map(int,input().split(" "))
s = [[0 for i in range(w)] for j in range(h)]
for i in range(h):
    tmp = list(input())
    for j in range(w):
        s[i][j] = tmp[j]
dp2 = [[-1 for i in range(w)] for j in range(h)]
dp3 = [[-1 for i in range(w)] for j in range(h)]
dp4 = [[-1 for i in range(w)] for j in range(h)]
dp5 = [[-1 for i in range(w)] for j in range(h)]
dp=[dp2,dp3,dp4,dp5]
def search(array,x,y,i,j,dp):
            if i>=0 and i<=x-1 and j>=0 and j<=y-1 and array[i][j] != "#":
                return -3+search2(array,x,y,i,j,dp)+search3(array,x,y,i,j,dp)+search4(array,x,y,i,j,dp)+search5(array,x,y,i,j,dp)
            else:
                return 0
def search2(array,x,y,i,j,dp):
            if i>=0 and i<=x-1 and j>=0 and j<=y-1 and array[i][j] != "#":
                if dp[0][i][j] == -1:
                    dp[0][i][j] = 1+search2(array,x,y,i-1,j,dp)
                    return dp[0][i][j]
                else:
                    return dp[0][i][j]
            elif i>=0 and i<=x-1 and j>=0 and j<=y-1:
                dp[0][i][j] = 0
            return 0

def search3(array,x,y,i,j,dp):
            if i>=0 and i<=x-1 and j>=0 and j<=y-1 and array[i][j] != "#":
                 if dp[1][i][j] == -1:
                    dp[1][i][j] = 1+search3(array,x,y,i+1,j,dp)
                    return dp[1][i][j]
                 else:
                    return dp[1][i][j]
            elif i>=0 and i<=x-1 and j>=0 and j<=y-1:
                dp[1][i][j] = 0
            return 0

def search4(array,x,y,i,j,dp):
            if i>=0 and i<=x-1 and j>=0 and j<=y-1 and array[i][j] != "#":
                if dp[2][i][j] == -1:
                    dp[2][i][j] = 1+search4(array,x,y,i,j-1,dp)
                    return dp[2][i][j]
                else:
                    return dp[2][i][j]
            elif i>=0 and i<=x-1 and j>=0 and j<=y-1:
                dp[2][i][j] = 0
            return 0

def search5(array,x,y,i,j,dp):
            if i>=0 and i<=x-1 and j>=0 and j<=y-1 and array[i][j] != "#":
                if dp[3][i][j] == -1:
                    dp[3][i][j] = 1+search5(array,x,y,i,j+1,dp)
                    return dp[3][i][j]
                else:
                    return  dp[3][i][j]
            elif i>=0 and i<=x-1 and j>=0 and j<=y-1:
                dp[3][i][j] = 0
            return 0

            
max = 1
for i in range(h):
    for j in range(w):
        a = search(s,h,w,i,j,dp)
        if max<a: 
            max= a

print(max)

Submission status: Runtime Error

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

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

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

     
for i in range(h):
    for j in range(w):
        if lst[i][j] == '.':
            if i == 0:
                U[i][j] = 1
            else:
                U[i][j] = U[i][j-1] + 1

for i in range(h-1, -1, -1):
    for j in range(w):
        if lst[i][j] == '.':
            if i == h-1:
                D[i][j] = 1
            else:
                D[i][j] = D[i][j-1] + 1

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] + U[i][j] + D[i][j] - 3
    ans = max(ans, max(x[i])
print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np
a=np.array([[0 if i!="." else 1 for i in input()]for j in range(h)])
s,t,u,p=np.zeros((h,w)),np.zeros((h,w)),np.zeros((h,w)),np.zeros((h,w))
for i in range(h):
    s[i]=(s[i-1]+1)*a[i]
    t[-i-1]=(t[-i]+1)*a[-i-1]
for i in range(w):
    u[:,j]=(u[:,j-1]+1)*a[:,j]
    p[:,-j-1]=(p[:,-j]+1)*a[:,-j-1]
print(np.max(s+t+u+p)-3)

Submission status: Runtime Error

Solution code:
from sys import stdin
def main():
  from itertools import repeat
  from builtins import range
  readline = stdin.readline
  h, w = map(int, readline().split())
  s = [readline().rstrip('\r\n') + '#' for _ in range(h)]
  s.append('#' * w)
  yoko = [[0] * w for _ in range(h)]
  for i in range(h):
    start = -1
    si = s[i]
    yokoi = yoko[i]
    for j in range(w + 1):
      if si[j] == '#':
        if start != -1:
          yokoi[start:j + 1] = repeat(t)
          start = -1
      else:
        if start == -1:
          start = j
  result = 0
  for i in range(w):
    start = -1
    for j in range(h + 1):
      if s[j][i] == '#':
        if start != -1:
          t = yoko_max + j - start - 1
          if t > result:
            result = t
          start = -1
      else:
        yji = yoko[j][i]
        if start == -1:
          start = j
          yoko_max = yji
        else:
          if yji > yoko_max:
            yoko_max = yji
  print(result)
main()

Submission status: Runtime Error

Solution code:
# import numpy as np
h,w = map(int,input().split())
field = []
accum=[[0 for i in range(w)] for j in range(h)]
accumrev=[[0 for i in range(w)] for j in range(h)]
stack = [[0 for i in range(w)] for j in range(h)]
stackrev = [[0 for i in range(w)] for j in range(h)]

for i in range(h):
    field.append(list(input()))
field = np.array(field)

for i in range(h):
    s = field[i]
    temp = 0
    for j in range(w):
        if s[j] == "#":
            accum[i][j] = 0
            temp = 0
        else:
            temp += 1
            accum[i][j] = temp
    accum[i][-1] = temp
for i in range(h):
    s = field[i]
    temp = 0
    for j in range(1,w+1):
        if s[-j] == "#":
            accumrev[i][-j] = 0
            temp = 0
        else:
            temp += 1
            accumrev[i][-j] = temp
    accumrev[i][0] = temp
# print(field)
# print(np.array(accum))
# print(np.array(accumrev))

nf = list(zip(*field))

for i in range(w):
    s = nf[i]
    temp = 0
    for j in range(h):
        if s[j] == "#":
            stack[j][i] = 0
            temp = 0
        else:
            temp += 1
            stack[j][i] = temp
    stack[-1][i] = temp

for i in range(w):
    s = nf[i]
    temp = 0
    for j in range(1,h+1):
        if s[-j] == "#":
            stackrev[-j][i] = 0
            temp = 0
        else:
            temp += 1
            stackrev[-j][i] = temp
    stackrev[0][i] = temp

# print(field)
# print(np.array(stack))
# print(np.array(stackrev))

# accum = np.array(accum)
# accumrev = np.array(accumrev)
# stack = np.array(stack)
# stackrev = np.array(stackrev)



ans = 0

for i in range(h):
    for j in range (w):
        temp = accum[i][j] + accumrev[i][j] + stackrev[i][j] + stack[i][j]-3
        if temp > ans:
            ans = temp
print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np
h,w = map(int,input().split())
field = []
accum=[[0 for i in range(w)] for j in range(h)]
accumrev=[[0 for i in range(w)] for j in range(h)]
stack = [[0 for i in range(w)] for j in range(h)]
stackrev = [[0 for i in range(w)] for j in range(h)]

for i in range(h):
    field.append(list(input()))
field = np.array(field)

for i in range(h):
    s = field[i]
    temp = 0
    for j in range(w):
        if s[j] == "#":
            accum[i][j] = 0
            temp = 0
        else:
            temp += 1
            accum[i][j] = temp
    accum[i][-1] = temp
for i in range(h):
    s = field[i]
    temp = 0
    for j in range(1,w+1):
        if s[-j] == "#":
            accumrev[i][-j] = 0
            temp = 0
        else:
            temp += 1
            accumrev[i][-j] = temp
    accumrev[i][0] = temp
# print(field)
# print(np.array(accum))
# print(np.array(accumrev))

nf = list(zip(*field))

for i in range(w):
    s = nf[i]
    temp = 0
    for j in range(h):
        if s[j] == "#":
            stack[j][i] = 0
            temp = 0
        else:
            temp += 1
            stack[j][i] = temp
    stack[-1][i] = temp

for i in range(w):
    s = nf[i]
    temp = 0
    for j in range(1,h+1):
        if s[-j] == "#":
            stackrev[-j][i] = 0
            temp = 0
        else:
            temp += 1
            stackrev[-j][i] = temp
    stackrev[0][i] = temp

# print(field)
# print(np.array(stack))
# print(np.array(stackrev))

# accum = np.array(accum)
# accumrev = np.array(accumrev)
# stack = np.array(stack)
# stackrev = np.array(stackrev)



ans = 0

for i in range(h):
    for j in range (w):
        temp = accum[i][j] + accumrev[i][j] + stackrev[i][j] + stack[i][j]-3
        if temp > ans:
            ans = temp
print(ans)

Submission status: Runtime Error

Solution code:
def main():
  _range, _input = range, stdin.readline
  h, w = map(int, _input().split())
  s = [_input() + '#' for _ in _range(h)]
  s.append('#' * (w + 1))
  t = [[-1] * w for _ in _range(h + 1)]
  tstart = [-1] * (w + 1)
  for i in _range(h + 1):
    ystart = -1
    si = s[i]
    ti = t[i]
    for j in _range(w + 1):
      tj = tstart[j]
      if si[j] == '#':
        if ystart != -1:
          n = j - ystart
          for k in _range(ystart, j):
            ti[k] += n
          ystart = -1
        if tj != -1:
          n = i - tj
          for k in _range(tj, i):
            t[k][j] += n
          tstart[j] = -1
      else:
        if ystart == -1:
          ystart = j
        if tj == -1:
          tstart[j] = i
  print(max(map(max, t)))
main()

Submission status: Runtime Error

Solution code:
h,w = map(int,input().split(" "))
s = [[0 for i in range(w)] for j in range(h)]
for i in range(h):
    tmp = list(input())
    for j in range(w):
        s[i][j] = tmp[j]
def search(array,x,y,i,j):
            if i>=0 and i<=x-1 and j>=0 and j<=y-1 and array[i][j] != "#":
                return 1+search2(array,x,y,i-1,j)+search3(array,x,y,i+1,j)+search4(array,x,y,i,j+1)+search5(array,x,y,i,j-1)
            else:
                return 0
def search2(array,x,y,i,j):
            if i>=0 and i<=x-1 and j>=0 and j<=y-1 and array[i][j] != "#":
                return 1+search2(array,x,y,i-1,j)
            else:
                return 0

def search3(array,x,y,i,j):
            if i>=0 and i<=x-1 and j>=0 and j<=y-1 and array[i][j] != "#":
                return 1+search3(array,x,y,i+1,j)
            else:
                return 0

def search4(array,x,y,i,j):
            if i>=0 and i<=x-1 and j>=0 and j<=y-1 and array[i][j] != "#":
                return 1+search4(array,x,y,i,j+1)
            else:
                return 0

def search5(array,x,y,i,j):
            if i>=0 and i<=x-1 and j>=0 and j<=y-1 and array[i][j] != "#":
                return 1+search5(array,x,y,i,j-1)
            else:
                return 0

            



max = 1
for i in range(h):
    for j in range(w):
        a = search(s,h,w,i,j)
        if max<a: 
            max= a
print(max)

Submission status: Runtime Error

Solution code:
h, w = map(int, input().split())
s = [_input() + '#' for _ in range(h)]
s.append('#' * (w + 1))
t = [[-1] * w for _ in range(h + 1)]
tstart = [-1] * (w + 1)
for i in range(h + 1):
  ystart = -1
  for j in range(w + 1):
    if s[i][j] == '#':
      if ystart != -1:
        for k in range(ystart, j):
          t[i][k] += j - ystart
        ystart = -1
      if tstart[j] != -1:
        for k in range(tstart[j], i):
          t[k][j] += i - tstart[j]
        tstart[j] = -1
    else:
      if ystart == -1:
        ystart = j
      if tstart[j] == -1:
        tstart[j] = i
print(_max(map(_max, t)))

Submission status: Runtime Error

Solution code:
def main():
  _max = max
  h, w = map(int, input().split())
  s = [input() + '#' for _ in range(h)]
  s.append('#' * (w + 1))

  rt = [[-1] * w for _ in range(h + 1)]

  tstart = [-1] * (w + 1)
  for i in range(h + 1):
    si = s[i]
    rti = rt[i]
    ystart = -1
    for j in range(w + 1):
      tj = tstart[j]
      if si[j] == '#':
        if ystart != -1:
          jy = j - ystart
          for k in range(ystart, j):
            rti[k] += jy
          ystart = -1
        if tj != -1:
          itj = i - tj
          for k in range(tj, i):
            rt[k][j] += itj
          tstart[j] = -1
      else:
        if ystart == -1:
          ystart = j
        if tj == -1:
          tstart[j] = i

  print(_max(sum(rt)))

main()

Submission status: Runtime Error

Solution code:
def main():
  h, w = map(int, input().split())
  s = [input() + '#' for _ in range(h)]
  s.append('#' * (w + 1))

  rt = [[-1] * w for _ in range(h + 1)]

  result = 0
  tstart = [-1] * (w + 1)
  for i in range(h + 1):
    si = s[i]
    rti = rt[i]
    ystart = -1
    for j in range(w + 1):
      tj = tstart[j]
      if si[j] == '#':
        if ystart != -1:
          jy = j - ystart
          for k in range(ystart, j):
            rti[k] += jy
            if rti[k] > result:
              result = rti[k]
          ystart = -1
        if tj != -1:
          itj = i - tj
          for k in range(tj, i):
            rt[k][j] += itj
            if rti[k][j] > result:
              result = rti[k][j]
          tstart[j] = -1
      else:
        if ystart == -1:
          ystart = j
        if tj == -1:
          tstart[j] = i

  print(result)

main()

Submission status: Runtime Error

Solution code:
def main():
  _max = max
  h, w = map(int, input().split())
  s = [input() + '#' for _ in range(h)]
  s.append('#' * (w + 1))

  rt = [[-1] * w for _ in range(h)]

  tstart = [-1] * (w + 1)
  for i in range(h + 1):
    si = s[i]
    rti = rt[i]
    ystart = -1
    for j in range(w + 1):
      if si[j] == '#':
        if ystart != -1:
          jy = j - ystart
          for k in range(ystart, j):
            rti[k] += jy
          ystart = -1
        tj = tstart[j]
        if tj != -1:
          itj = i - tj
          for k in range(tj, i):
            rt[k][j] += itj
          tstart[j] = -1
      else:
        if ystart == -1:
          ystart = j
        if tstart[j] == -1:
          tstart[j] = i

  print(_max(_max(l) for l in rt))

main()

Submission status: Runtime Error

Solution code:
def main():
  h, w = map(int, input().split())
  s = [input() + '#' for _ in range(h)]
  s.append('#' * (w + 1))

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

  for i in range(h + 1):
    si = s[i]
    ystart = -1
    tstart = [-1] * w
    for j in range(w + 1):
      if si[j] == '#':
        if ystart != -1:
          for k in range(ystart, j):
            yoko[i][k] = j - ystart
          ystart = -1
        if tstart[j] != -1:
          for k in range(tstart[j], i):
            tate[k][j] = i - tstart[j]
          tstart[j] = -1
      else:
        if ystart == -1:
          ystart = j
        if tstart[j] == -1:
          tstart[j] = i

  result = 0
  for i in range(h):
    yokoi = yoko[i]
    tatei = tate[i]
    for j in range(w):
      t = yokoi[j] + tatei[j] - 1
      if t > result:
        result = t

  print(result)

main()

Submission status: Runtime Error

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

yoko = [[0] * w for _ in range(h)]
for i in range(h):
  si = s[i]
  for j in range(w):
    if si[j] == '.':
      start = j
      jj = j + 1
      break
  for j in range(jj, w + 1):
    if si[j] == '#':
      if start != -1:
        for k in range(start, j):
          yoko[i][k] = j - start
        start = -1
    else:
      if start == -1:
        start = j

tate = [[0] * w for _ in range(h)]
for i in range(w):
  if s[0][i] == '.':
    start = 0
  else:
    start = -1
  for j in range(1, h + 1):
    if s[j][i] == '#':
      if start != -1:
        for k in range(start, j):
          tate[k][i] = j - start
        start = -1
    else:
      if start == -1:
        start = j

result = 0
for i in range(h):
  yokoi = yoko[i]
  tatei = tate[i]
  for j in range(w):
    t = yokoi[j] + tatei[j] - 1
    if t > result:
      result = t

print(result)

Submission status: Runtime Error

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

yoko = [[0] * w for _ in range(h)]
for i in range(h):
  si = s[i]
  for j in range(w):
    if si[j] == '.':
      start = j
      break
  for j in range(start + 1, w + 1):
    if si[j] == '#':
      if start != -1:
        for k in range(start, j):
          yoko[i][k] = j - start
        start = -1
    else:
      if start == -1:
        start = j

tate = [[0] * w for _ in range(h)]
for i in range(w):
  if s[0][i] == '.':
    start = 0
  else:
    start = -1
  for j in range(1, h + 1):
    if s[j][i] == '#':
      if start != -1:
        for k in range(start, j):
          tate[k][i] = j - start
        start = -1
    else:
      if start == -1:
        start = j

result = 0
for i in range(h):
  yokoi = yoko[i]
  tatei = tate[i]
  for j in range(w):
    t = yokoi[j] + tatei[j] - 1
    if t > result:
      result = t

print(result)

Submission status: Runtime Error

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

yoko = [[0] * w for _ in range(h)]
for i in range(h):
  si = s[i]
  for j in range(w):
    if si[j] == '.':
      start = j
      break
  for j in range(start, w + 1):
    if si[j] == '#':
      if start != -1:
        for k in range(start, j):
          yoko[i][k] = j - start
        start = -1
    else:
      if start == -1:
        start = j

tate = [[0] * w for _ in range(h)]
for i in range(w):
  for j in range(h):
    if s[j][i] == '.':
      start = j
      break
  for j in range(start, h + 1):
    if s[j][i] == '#':
      if start != -1:
        for k in range(start, j):
          tate[k][i] = j - start
        start = -1
    else:
      if start == -1:
        start = j

result = 0
for i in range(h):
  yokoi = yoko[i]
  tatei = tate[i]
  for j in range(w):
    t = yokoi[j] + tatei[j] - 1
    if t > result:
      result = t

print(result)

Submission status: Runtime Error

Solution code:
import numpy as np
H,W = mmap(int, input().split())
S = [[] for i in range(H)]
for i in range(H):
  S[i] = list(input())
S = np.array(S)
S = np.where(S=="#",0,1)

l = np.zeros((H,W))
l[:,-1] = S[:,-1]
r = np.zeros((H,W))
r[:,0] = S[:,0]
u = np.zeros((H,W))
u[-1] = S[-1]
d = np.zeros((H,W))
d[0] = S[0]

for i in range(W-2,-1,-1):
  l[:,i] = (l[:,i+1]+1)*S[:,i]
for i in range(1,W):
  r[:,i] = (r[:,i-1]+1)*S[:,i]
for i in range(H-2,-1,-1):
  u[i] = (u[i+1]+1)*S[i]
for i in range(1,H):
  d[i] = (d[i-1]+1)*S[i]

print(int(np.max(l+r+u+d-3)))

Submission status: Runtime Error

Solution code:
import numpy as np
H,W = mmap(int, input().split())
S = [[] for i in range(H)]
for i in range(H):
  S[i] = [input().split()]
S = np.array(S)
S = np.where(S=="#",0,1)

l = np.zeros((H,W))
l[:,-1] = S[:,-1]
r = np.zeros((H,W))
r[:,0] = S[:,0]
u = np.zeros((H,W))
u[-1] = S[-1]
d = np.zeros((H,W))
d[0] = S[0]

for i in range(W-2,-1,-1):
  l[:,i] = (l[:,i+1]+1)*S[:,i]
for i in range(1,W):
  r[:,i] = (r[:,i-1]+1)*S[:,i]
for i in range(H-2,-1,-1):
  u[i] = (u[i+1]+1)*S[i]
for i in range(1,H):
  d[i] = (d[i-1]+1)*S[i]

print(int(np.max(l+r+u+d-3)))

Submission status: Runtime Error

Solution code:
# via. https://qiita.com/ys-0-sy/items/e5a5b344e8549c1dd280

import numpy as np
import sys
from numba import njit

@njit
def calc(a):
    # 横方向
    for j in range(a.shape[0] - 1):
        prev = 0
        start = 0
        for i in range(a.shape[1]):
            if a[j, i] > 0:
                if prev == 0:
                    start = i
                    prev = 1
            else:
                if prev == 1:
                    num = i - start
                    for k in range(start, i):
                        a[j, k] = num
                    prev = 0
    # 縦方向
    for i in range(a.shape[1] - 1):
        prev = 0
        start = 0
        for j in range(a.shape[0]):
            if a[j, i] > 0:
                if prev == 0:
                    start = j
                    prev = 1
            else:
                if prev == 1:
                    num = j - start - 1
                    for k in range(start, j):
                        a[k, i] += num
                    prev = 0


cin = sys.stdin.buffer
H, W = map(int, cin.readline().split())
a = np.empty((H + 1, W + 1), dtype='i4')
a[:H, :] = (np.frombuffer(cin.read(H * (W + 1)), dtype='B') == ord('.')).reshape((H, W + 1))
a[H] = np.zeros(W + 1, dtype='i4')

calc(a)
print(a.max())

Submission status: Runtime Error

Solution code:
h, w = map(int, input().split())
s = []
s_h = []
for _ in range(h):
    k = list(input())
    s.append(k)
    s_h.append(k.count("."))
s_k = list(map(list, zip(*s)))
s_k = list(map(lambda x: x.count("."), s_k))

a = []
for hh in range(h):
    for ww in range(w):
        if s[hh][ww] == ".":
            if s[hh]
            ans = s_k[ww] + s_h[hh] - 1
            a.append(ans)
        else:
            a.append(0)
print(max(a))