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:
import sys
sys.setrecursionlimit(10 ** 9)

import functools
@functools.lru_cache(maxsize = None)

def main():
    #input
    H, W = map(int, input().split())
    lst = [['#'] * (W + 2)]
    lst += [['#'] + list(input()) + ['#'] for _ in range(H)]
    lst += [['#'] * (W + 2)]

    u_table = [[-1] * (W + 2) for _ in range(W + 2)]
    d_table = [[-1] * (W + 2) for _ in range(W + 2)]
    r_table = [[-1] * (W + 2) for _ in range(W + 2)]
    l_table = [[-1] * (W + 2) for _ in range(W + 2)]

    def u(i, j): #up方向に何マス光が伸びるかを数える
        if u_table[i][j] != -1:
            return u_table[i][j]
        if lst[i][j] == '#':
            u_table[i][j] = 0
            return 0
        else:
            u_table[i][j] = u(i - 1, j) + 1
            return u_table[i][j]
    
    def d(i, j):
        if d_table[i][j] != -1:
            return d_table[i][j]
        if lst[i][j] == '#':
            d_table[i][j] = 0
            return 0
        else:
            d_table[i][j] = d(i + 1, j) + 1
            return d_table[i][j]
    
    def r(i, j):
        if r_table[i][j] != -1:
            return r_table[i][j]
        if lst[i][j] == '#':
            r_table[i][j] = 0
            return 0
        else:
            r_table[i][j] = r(i, j + 1) + 1
            return r_table[i][j]

    def l(i, j):
        if l_table[i][j] != -1:
            return l_table[i][j]
        if lst[i][j] == '#':
            l_table[i][j] = 0
            return 0
        else:
            l_table[i][j] = l(i, j - 1) + 1
            return l_table[i][j]

    #スタートマスを変えながら最大の範囲の広さを検索
    ans = 0
    for i in range(1, H + 1):
        for j in range(1, W + 1):
            if lst[i][j] == '.': #光源を置く場所が障害物でないとき
                tmp = u(i, j) + d(i, j) + r(i, j) + l(i, j) - 3
                # print ('(i, j) = ', i, j, tmp)
                ans = max(ans, tmp)
    print (ans)
    return 

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(10 ** 9)

def main():
    #input
    H, W = map(int, input().split())
    lst = [['#'] * (W + 2)]
    lst += [['#'] + list(input()) + ['#'] for _ in range(H)]
    lst += [['#'] * (W + 2)]

    u_table = [[-1] * (W + 2) for _ in range(W + 2)]
    d_table = [[-1] * (W + 2) for _ in range(W + 2)]
    r_table = [[-1] * (W + 2) for _ in range(W + 2)]
    l_table = [[-1] * (W + 2) for _ in range(W + 2)]

    def u(i, j): #up方向に何マス光が伸びるかを数える
        if u_table[i][j] != -1:
            return u_table[i][j]
        if lst[i][j] == '#':
            u_table[i][j] = 0
            return 0
        else:
            u_table[i][j] = u(i - 1, j) + 1
            return u_table[i][j]
    
    def d(i, j):
        if d_table[i][j] != -1:
            return d_table[i][j]
        if lst[i][j] == '#':
            d_table[i][j] = 0
            return 0
        else:
            d_table[i][j] = d(i + 1, j) + 1
            return d_table[i][j]
    
    def r(i, j):
        if r_table[i][j] != -1:
            return r_table[i][j]
        if lst[i][j] == '#':
            r_table[i][j] = 0
            return 0
        else:
            r_table[i][j] = r(i, j + 1) + 1
            return r_table[i][j]

    def l(i, j):
        if l_table[i][j] != -1:
            return l_table[i][j]
        if lst[i][j] == '#':
            l_table[i][j] = 0
            return 0
        else:
            l_table[i][j] = l(i, j - 1) + 1
            return l_table[i][j]

    #スタートマスを変えながら最大の範囲の広さを検索
    ans = 0
    for i in range(1, H + 1):
        for j in range(1, W + 1):
            if lst[i][j] == '.': #光源を置く場所が障害物でないとき
                tmp = u(i, j) + d(i, j) + r(i, j) + l(i, j) - 3
                # print ('(i, j) = ', i, j, tmp)
                ans = max(ans, tmp)
    print (ans)
    return 

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
import sys
def main():
    input=sys.stdin.readline
    def U(h,w):
        if S[h][w]=="#":ret=0
        elif h==0:ret=1
        else:ret=U(h-1,w)+1
        return ret
    def D(h,w):
        if S[h][w]=="#":ret=0
        elif h==H-1:ret=1
        else:ret=D(h+1,w)+1
        return ret
    def L(h,w):
        if S[h][w]=="#":ret=0
        elif w==0:ret=1
        else:ret=L(h,w-1)+1
        return ret
    def R(h,w):
        if S[h][w]=="#":ret=0
        elif w==W-1:ret=1
        else:ret=R(h,w+1)+1
        return ret
    H,W=map(int,input().split())
    S=[]
    for _ in range(H):
        S.append(input())
    ans=0
    for i in range(H):
        for j in range(W):
            l=U(i,j)+D(i,j)+L(i,j)+R(i,j)-3
            ans=max(ans,l)
    print(ans)

if __name__=="__main__":
    main()

Submission status: Runtime Error

Solution code:
import logging

logging.basicConfig(level=logging.INFO, format="%(message)s")
#logging.disable(logging.CRITICAL)

H, W = (int(x) for x in input().split())

fields = []
fields.extend([list(input()) for _ in range(H)])

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


logging.info(fields)
logging.info(L[0][1])

for i in range(H):
    for j in range(W):
        if fields[i][j] == '#':
            L[i][j] = 0
            U[i][j] = 0

        elif fields[i][j] == ".":
            if j == 0:
                L[i][j] = 1
            elif j > 0 :
                L[i][j] = L[i][j - 1] + 1

            if i == 0:
                U[i][j] = 1
            elif i > 0:
                U[i][j] = U[i - 1][j] + 1
        
            
        if fields[i][W - j - 1] == "#":
            R[i][W - j - 1] = 0
        elif fields[i][W - j - 1] == ".":
            if j == 0:
                R[i][W - j - 1] = 1
            elif j > 0:
                R[i][W - j - 1] = R[i][W - j] + 1
                
        
        if fields[H - i - 1][j] == "#":
            D[H - i - 1][j] = 0
            
        elif fields[H - i - 1][j] == ".":
            if i == 0:
                D[H - i - 1][j] = 1
            elif i > 0:
                D[H - i - 1][j] = D[H - i][j] + 1


max_count = 0
for i in range(H):
    for j in range(W):
        sum = L[i][j] + R[i][j] + D[i][j] + U[i][j] - 3
        if max_count < sum:
            max_count = sum


print(max_count)

Submission status: Runtime Error

Solution code:
# ABC129_D

H, W = map(int, input().split())
squares = []
x = []
y = []

for i in range(H):
    squares.append([])
    x.append([])
    y.append([])
    s = input()
    for j in range(W):
        if(s[j] == "#"):
            squares[i].append(0)
            x[i].append([])
            y[i].append([])
        else:
            squares[i].append(1)
            x[i].append([])
            y[i].append([])

for i in range(H):
    for j in range(W):
        if(squares[i][j] == 0):
            x[i][j] = 0
        else:
            if(j == 0):
                count = 0
                tmpj = j
                while(squares[i][tmpj + 1] != 0 and tmpj < W - 1):
                    count = count + 1
                    if (tmpj + 1 <= W - 2):
                        tmpj = tmpj + 1
                    else:
                        for k in range(j, tmpj + 1):
                            x[i][k] = count
                        j = tmpj
                        break
                else:
                    for k in range(j, tmpj + 1):
                        x[i][k] = count
                    j = tmpj
            elif(j == W - 1):
                x[i][j] = x[i][j - 1]
            else:
                if(x[i][j - 1] != 0):
                    x[i][j] = x[i][j - 1]
                else:
                    count = 0
                    if (j <= W - 1):
                        tmpj = j
                        while(squares[i][tmpj + 1] != 0 and tmpj < W - 1):
                            count = count + 1
                            if (tmpj + 1 <= W - 2):
                                tmpj = tmpj + 1
                            else:
                                for k in range(j, tmpj + 1):
                                    x[i][k] = count
                                j = tmpj
                                break
                        else:
                            for k in range(j, tmpj + 1):
                                x[i][k] = count
                            j = tmpj

for j in range(W):
    for i in range(H):
        if(squares[i][j] == 0):
            y[i][j] = 0
        else:
            if(i == 0):
                count = 0
                tmpi = i
                while(squares[tmpi + 1][j] != 0 and tmpi < H - 1):
                    count = count + 1
                    if (tmpi + 1 <= H - 2):
                        tmpi = tmpi + 1
                    else:
                        for p in range(i, tmpi + 1):
                            y[p][j] = count
                        i = tmpi
                        break
                else:
                    for p in range(i, tmpi + 1):
                        y[p][j] = count
                    i = tmpi
            elif(i == H - 1):
                y[i][j] = y[i - 1][j]
            else:
                if(y[i - 1][j] != 0):
                    y[i][j] = y[i - 1][j]
                else:
                    count = 0
                    if (i <= H - 1):
                        tmpi = i
                        while(squares[tmpi + 1][j] != 0 and tmpi < H - 1):
                            count = count + 1
                            if (tmpi + 1 <= H - 2):
                                tmpi = tmpi + 1
                            else:
                                for p in range(i, tmpi + 1):
                                    y[p][j] = count
                                i = tmpi
                                break
                        else:
                            for p in range(i, tmpi + 1):
                                y[p][j] = count
                            i = tmpi
                            
max = 0
for j in range(W):
    for i in range(H):
        if(squares[i][j] == 1):
            tmpAns = x[i][j] + y[i][j] + 1
            if(tmpAns > max):
                max = tmpAns

print(max)

Submission status: Runtime Error

Solution code:
# ABC129_D

H, W = map(int, input().split())
squares = []
x = []
y = []

for i in range(H):
    squares.append([])
    x.append([])
    y.append([])
    s = input()
    for j in range(W):
        if(s[j] == "#"):
            squares[i].append(0)
            x[i].append([])
            y[i].append([])
        else:
            squares[i].append(1)
            x[i].append([])
            y[i].append([])

for i in range(H):
    for j in range(W):
        if(squares[i][j] == 0):
            x[i][j] = 0
        else:
            if(j == 0):
                count = 0
                if (j <= W - 1):
                    tmpj = j
                    while(squares[i][tmpj + 1] != 0 and tmpj < W - 1):
                        count = count + 1
                        if (tmpj + 1 <= W - 2):
                            tmpj = tmpj + 1
                        else:
                            x[i][j] = count
                            break
                    else:
                        x[i][j] = count
            elif(j == W - 1):
                x[i][j] = x[i][j - 1]
            else:
                if(x[i][j - 1] != 0):
                    x[i][j] = x[i][j - 1]
                else:
                    count = 0
                    if (j <= W - 1):
                        tmpj = j
                        while(squares[i][tmpj + 1] != 0 and tmpj < W - 1):
                            count = count + 1
                            if (tmpj + 1 <= W - 2):
                                tmpj = tmpj + 1
                            else:
                                x[i][j] = count
                                break
                        else:
                            x[i][j] = count

for j in range(W):
    for i in range(H):
        if(squares[i][j] == 0):
            y[i][j] = 0
        else:
            if(i == 0):
                count = 0
                if (i <= H - 1):
                    tmpi = i
                    while(squares[tmpi + 1][j] != 0 and tmpi < H - 1):
                        count = count + 1
                        if (tmpi + 1 <= H - 2):
                            tmpi = tmpi + 1
                        else:
                            y[i][j] = count
                            break
                    else:
                        y[i][j] = count

            elif(i == H - 1):
                y[i][j] = y[i - 1][j]
            else:
                if(y[i - 1][j] != 0):
                    y[i][j] = y[i - 1][j]
                else:
                    count = 0
                    if (i <= H - 1):
                        tmpi = i
                        while(squares[tmpi + 1][j] != 0 and tmpi < H - 1):
                            count = count + 1
                            if (tmpi + 1 <= H - 2):
                                tmpi = tmpi + 1
                            else:
                                y[i][j] = count
                                break
                        else:
                            y[i][j] = count
max = 0
for j in range(W):
    for i in range(H):
        tmp = x[i][j] + y[i][j] + 1
        if(tmp > max):
            max = tmp

print(max)

Submission status: Runtime Error

Solution code:
def D_Lamp():
    h, w = map(int, input().split())
    S = [[0 for i in range(w)] for j in range(h)]
    for row in range(h):
        si = input()
        for col in range(w):
            if "." == si[col]:
                S[row][col] = 1
    S_row = calc_point_row(h,w,S)
    S_col = calc_point_col(h,w,S)
    # 
    num_max = 0
    for row in range(h):
        for col in range(w):
            s_num = S_row[row][col] + S_col[row][col] - 1
            num_max = max(num_max, s_num)
    print(num_max)
def calc_point_row(h,w,S):
    S_tmp = [[0 for i in range(w)] for j in range(h)]
    for row in range(h):
        sum_w = 0
        for col in range(w):
            if 1 == S[row][col]:
                sum_w += 1
            elif (sum_w == 0):
                S_tmp[row][col] = 0
            else:
                for x in range(sum_w):
                    S_tmp[row][col-x-1] = sum_w
                sum_w = 0
        if (sum_w == w):
            for x in range(sum_w):
                S_tmp[row][i] = sum_w
        elif (sum_w != 0):
            for x in range(sum_w):
                S_tmp[row][w-x-1] = sum_w
    return S_tmp
def calc_point_col(h,w,S):
    S_tmp = [[0 for i in range(w)] for j in range(h)]
    for col in range(w):
        sum_w = 0
        for row in range(h):
            if 1 == S[row][col]:
                sum_w += 1
            elif (sum_w == 0):
                S_tmp[row][col] = 0
            else:
                for x in range(sum_w):
                    S_tmp[row-x-1][col] = sum_w
                sum_w = 0
        if (sum_w == h):
            for x in range(sum_w):
                S_tmp[x][col] = sum_w
        elif (sum_w != 0):
            for x in range(sum_w):
                S_tmp[h-x-1][col] = sum_w
    return S_tmp

if __name__ == "__main__":
    D_Lamp()

Submission status: Runtime Error

Solution code:
import numpy as np

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

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

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

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

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

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

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

print(ans)

Submission status: Runtime Error

Solution code:
def U(h,w):
    if S[h][w]=="#":ret=0
    elif h==0:ret=1
    else:ret=U(h-1,w)+1
    return ret
def D(h,w):
    if S[h][w]=="#":ret=0
    elif h==H-1:ret=1
    else:ret=D(h+1,w)+1
    return ret
def L(h,w):
    if S[h][w]=="#":ret=0
    elif w==0:ret=1
    else:ret=L(h,w-1)+1
    return ret
def R(h,w):
    if S[h][w]=="#":ret=0
    elif w==W-1:ret=1
    else:ret=R(h,w+1)+1
    return ret

H,W=map(int,input().split())
S=[]
for _ in range(H):
    S.append(input())
ans=0
for i in range(H):
    for j in range(W):
        l=U(i,j)+D(i,j)+L(i,j)+R(i,j)-3
        ans=max(ans,l)
print(ans)

Submission status: Runtime Error

Solution code:
H,W = map(int,input().split())
S = [list(input()) for _ in range(H)]
def leftLamp(i,j):
  if S[i][j] =="#":
    return 0
  elif j == 0:
    return 1
  else:
    return leftLamp(i,j-1) + 1
def rightLamp(i,j):
  if S[i][j] == "#":
    return 0
  elif j == W-1:
    return 1
  else:
    return rightLamp(i,j+1) + 1
def upLamp(i,j):
  if S[i][j] == "#":
    return 0
  elif i == 0:
    return 1
  else:
    return upLamp(i-1,j) + 1
def downLamp(i,j):
  if S[i][j] == "#":
    return 0 
  elif i == H-1:
    return 1
  else:
    return downLamp(i+1,j) + 1
def lamp(i,j):
  return leftLamp(i,j) + rightLamp(i,j) + upLamp(i,j) + downLamp(i,j) - 3

lmax = 0
for i in range(H):
  for j in range(W):
    temp = lamp(i,j)
    if lmax < temp:
      lmax = temp
print(lmax)

Submission status: Runtime Error

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

h = []
v = []
for i in range(H):
    a = 0
    h.append([])
    v.append([])
    for j in range(W):
        if S[i][j] == '#':
            a = 0
        else:
            a += 1
        h[i].append(a)
    for j in range(W - 1, -1, -1):
        if S[i][j] == '#':
            a = 0
        else:
            if a == 0:
                a = h[i][j]
            h[i][j] = a

for i in range(W):
    a = 0
    for j in range(H):
        if S[j][i] == '#':
            a = 0
        else:
            a += 1
        v[j].append(a)
    for j in range(H - 1, -1, -1):
        if S[j][i] == '#':
            a = 0
        else:
            if a == 0:
                a = v[j][i]
            v[j][i] = a

ans = 0
for i in range(H):
    for j in range(W):
        ans = max(ans, h[i][j] + v[i][j])
print(ans - 1)
H, W = map(int, input().split())

Submission status: Runtime Error

Solution code:
import numpy as np

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

field = []

l = np.zeros((h+2,w+2),dtype=np.int64)
r = np.zeros((h+2,w+2),dtype=np.int64)
u = np.zeros((h+2,w+2),dtype=np.int64)
d = np.zeros((h+2,w+2),dtype=np.int64)
tot = np.zeros((h,w),dtype=np.int64)

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

field = np.pad(field,(1,1),"constant",constant_values="#")

# print(field)

for i in range(h+2):
    for j in range(w+1):
        if field[i][j+1] == ".":
            l[i][j+1] = l[i][j] + 1
        else:
            continue

for i in range(h+2):
    for j in range(1,w+1):
        if field[i][-j-1] == ".":
            r[i][-j-1] = r[i][-j] + 1
        else:
            continue

for i in range(w+2):
    for j in range(h+1):
        if field[j+1][i] == ".":
            u[j+1][i] = u[j][i] + 1
        else:
            continue

for i in range(w+2):
    for j in range(1,h+1):
        if field[-j-1][i] == ".":
            d[-j-1][i] = d[-j][i] + 1
        else:
            continue

# print(l)
# print(r)
# print(u)
# print(d)

for i in range(h):
    for j in range(w):
        tot[i][j] = l[i+1][j+1]+r[i+1][j+1]+u[i+1][j+1]+d[i+1][j+1]-3

# print(tot)

print(np.max(tot))

Submission status: Runtime Error

Solution code:
import numpy as np

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

field = []

l = np.zeros((h+2,w+2))
r = np.zeros((h+2,w+2))
u = np.zeros((h+2,w+2))
d = np.zeros((h+2,w+2))
tot = np.zeros((h,w))

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

field = np.pad(field,(1,1),"constant",constant_values="#")

# print(field)

for i in range(h+2):
    for j in range(w+1):
        if field[i][j+1] == ".":
            l[i][j+1] = l[i][j] + 1
        else:
            continue

for i in range(h+2):
    for j in range(1,w+1):
        if field[i][-j-1] == ".":
            r[i][-j-1] = r[i][-j] + 1
        else:
            continue

for i in range(w+2):
    for j in range(h+1):
        if field[j+1][i] == ".":
            u[j+1][i] = u[j][i] + 1
        else:
            continue

for i in range(w+2):
    for j in range(1,h+1):
        if field[-j-1][i] == ".":
            d[-j-1][i] = d[-j][i] + 1
        else:
            continue

# print(l)
# print(r)
# print(u)
# print(d)

for i in range(h):
    for j in range(w):
        tot[i][j] = l[i+1][j+1]+r[i+1][j+1]+u[i+1][j+1]+d[i+1][j+1]-3

# print(tot)

print(int(np.max(tot)))

Submission status: Runtime Error

Solution code:
import numpy as np

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

field = []

l = np.zeros((h+2,w+2))
r = np.zeros((h+2,w+2))
u = np.zeros((h+2,w+2))
d = np.zeros((h+2,w+2))
tot = np.zeros((h,w))

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

field = np.pad(field,(1,1),"constant",constant_values="#")

# print(field)

for i in range(h+2):
    for j in range(w+1):
        if field[i][j+1] == ".":
            l[i][j+1] = l[i][j] + 1
        else:
            continue

for i in range(h+2):
    for j in range(1,w+1):
        if field[i][-j-1] == ".":
            r[i][-j-1] = r[i][-j] + 1
        else:
            continue

for i in range(w+2):
    for j in range(h+1):
        if field[j+1][i] == ".":
            u[j+1][i] = u[j][i] + 1
        else:
            continue

for i in range(w+2):
    for j in range(1,h+1):
        if field[-j-1][i] == ".":
            d[-j-1][i] = d[-j][i] + 1
        else:
            continue
l = l

# print(l)
# print(r)
# print(u)
# print(d)

for i in range(h):
    for j in range(w):
        tot[i][j] = l[i+1][j+1]+r[i+1][j+1]+u[i+1][j+1]+d[i+1][j+1]-3

# print(tot)

print(int(np.max(tot)))

Submission status: Runtime Error

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

field = [[0 for i in range(W)] for j in range(H)]
for i in range(H):
    field[i] = str(input());

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

for i in range(H):
    for j in range(W):
        if field[i][j] == ".":
            ii = i
            jj = j
            while (ii < H and field[ii][jj] == "."):
                L[i][j] += 1
                ii += 1
            ii = i
            jj = j
            while (ii >= 0 and field[ii][jj] == "."):
                L[i][j] += 1
                ii -= 1
            ii = i
            jj = j
            while (jj < W and field[ii][jj] == "."):
                L[i][j] += 1
                jj += 1
            ii = i
            jj = j
            while (jj >= 0 and field[ii][jj] == "."):
                L[i][j] += 1
                jj -= 1


ans = max(L)-3
ans = max(ans)

print(ans)

Submission status: Runtime Error

Solution code:
def u(y,x):
    if grid[y][x]=="#":ret=0
    else:ret=u(y-1,x)+1
    return ret
def d(y,x):
    if grid[y][x]=="#":ret=0
    else:ret=d(y+1,x)+1
    return ret
def l(y,x):
    if grid[y][x]=="#":ret=0
    else:ret=l(y,x-1)+1
    return ret
def r(y,x):
    if grid[y][x]=="#":ret=0
    else:ret=r(y,x+1)+1
    return ret

H,W=map(int,input().split())
grid=["#"*(W+2)]
for _ in range(H):
    grid.append("#"+input()+"#")
grid.append("#"*(W+2))
ans=0
for y in range(H+2):
    for x in range(W+2):
        U,D,L,R=u(y,x),d(y,x),l(y,x),r(y,x)
        light=U+D+L+R-3+[U,D,L,R].count(0)
        ans=max(ans,light)

print(ans)

Submission status: Runtime Error

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

x = [[0 for _ in range(W)] for _ in range(H)]
y = [[0 for _ in range(W)] for _ in range(H)]

for i, j in ((i, j) for i in range(H) for j in range(W) if S[i][j] == '.'):
    if x[i][j] == 0:
        w = len(list(takewhile(lambda k: S[i][k] == '.', range(j, W))))
        for k in range(j, j + w):
            x[i][k] = w
    if y[i][j] == 0:
        h = len(list(takewhile(lambda k: S[k][j] == '.', range(i, H))))
        for l in range(i, i + h):
            y[l][j] = h

ans = max(
    x[i][j] + y[i][j] - 1
    for i in range(H)
    for j in range(W)
)
# 出力
print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np

#メイン処理
H,W = map(int,input().split())
S = []
 
#二次元配列
for _ in range(H):
    a = input()
    S.append(list(a))
 
maxlamp = 0

# L = [[0] * W for i in range(H)] #左
# R = [[0] * W for i in range(H)] #右
# D = [[0] * W for i in range(H)] #下
# U = [[0] * W for i in range(H)] #上

L = np.zeros((H,W))
R = np.zeros((H,W))
D = np.zeros((H,W))
U = np.zeros((H,W))
 
#Lの計算
for _h in range(H):
    for _w in range(W):
        if S[_h][_w] != '#':
            if _w == 0:
                L[_h][_w] = 1
            elif _w > 0:
                L[_h][_w] = L[_h][_w-1] + 1
    
            if _h == 0:
                U[_h][_w] = 1
            elif _h > 0:
                U[_h][_w] = U[_h-1][_w] + 1
 
for _h in range(H-1,-1,-1):
    for _w in range(W-1,-1,-1):
        if S[_h][_w] != '#':
            if _w == W-1:
                R[_h][_w] = 1
            elif _w < W-1:
                R[_h][_w] = R[_h][_w+1] + 1
 
            if _h == H-1:
                D[_h][_w] = 1
                
            elif _h < H-1:
                D[_h][_w] = D[_h+1][_w] + 1
        
            tmp = L[_h][_w] + R[_h][_w] + U[_h][_w] + D[_h][_w] - 3
            maxlamp = max(maxlamp,tmp)
 
print(int(maxlamp))

Submission status: Runtime Error

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

lights_arr = []
for h in range(H):
  for w in range(W):
    if F[h][w] == ".":
      h_cnt = 0
      w_cnt = 0
      
      i = h
      while i < H:
        if F[i][w] == "#":
          break
        h_cnt += 1
        i += 1
        
      i = h
      while i >= 0:
        if F[i][w] == "#":
          break
        h_cnt += 1
        i -= 1
        
      j = w
      while j < W:
        if F[h][j] == "#":
          break
        w_cnt += 1
        j += 1
        
      j = w
      while j < W:
        if F[h][j] == "#":
          break
        w_cnt += 1
        j -= 1
       
      
      lights = h_cnt + w_cnt -3
      
      lights_arr.append(lights)
      
print(max(lights_arr))

Submission status: Runtime Error

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

a = [max([i.count('.') for i in S[i].split('#')]) for i in range(len(S))]
b = [S[a.index(max(a))][i] for i in range(len(a))]
print(max(a) + len(b) - 1)

Submission status: Runtime Error

Solution code:
hw = list(map(int, input().split()))
# "."は障害物なし、"#"は障害物
s = [input() for l in range(hw[0])]
result = 0
A
# 各方向ごとの照らせるマス数を座標ごとに少ない計算量で事前計算することで、総計算量を定量的にする
L = [[0 for i in range(hw[1])] for j in range(hw[0])]
for i in range(hw[0]):
    for j in range(hw[1]):
        if s[i][j] != "#":
            if j == 0:
                L[i][j] = 1
            else:
                L[i][j] = L[i][j-1]+1
                
R = [[0 for i in range(hw[1])] for j in range(hw[0])]
for i in range(hw[0]):
    for j in range(hw[1]-1, 0, -1):
        if s[i][j] != "#":
            if j == hw[1]-1:
                R[i][j] = 1
            else:
                R[i][j] = R[i][j+1]+1
                
U = [[0 for i in range(hw[1])] for j in range(hw[0])]
for i in range(hw[0]):
    for j in range(hw[1]):
        if s[i][j] != "#":
            if i == 0:
                U[i][j] = 1
            else:
                U[i][j] = U[i-1][j]+1
                
D = [[0 for i in range(hw[1])] for j in range(hw[0])]
for i in range(hw[0]-1, 0, -1):
    for j in range(hw[1]):
        if s[i][j] != "#":
            if i == hw[0]-1:
                D[i][j] = 1
            else:
                D[i][j] = D[i+1][j]+1
                
# 4方向の明かりの合計値の最大を抽出
for i in range(hw[0]):
    for j in range(hw[1]):
        if s[i][j] != "#":
            tmp = L[i][j] + R[i][j] + U[i][j] + D[i][j] - 3
            if result < tmp:
                result = tmp
                
print(result)

Submission status: Runtime Error

Solution code:
def solve(string):
    h, w, *s = string.split()
    h, w = map(int, [h, w])
    hg = []
    hi = []
    vg = []
    vi = []

    for _s in s:
        gn = 0
        _hi = [0] * w
        _hg = []
        c = 0
        for i, __s in enumerate(_s):
            if __s == "#":
                _hi[i] = -1
                gn += 1
                _hg.append(c)
                c = 0
                continue
            _hi[i] = gn
            c += 1
        _hg.append(c)
        hg.append(_hg)
        hi.append(_hi)
    for _s in zip(*s):
        gn = 0
        _vi = [0] * h
        _vg = []
        c = 0
        for i, __s in enumerate(_s):
            if __s == "#":
                _vi[i] = -1
                gn += 1
                _vg.append(c)
                c = 0
                continue
            _vi[i] = gn
            c += 1
        _vg.append(c)
        vg.append(_vg)
        vi.append(_vi)
        ans = 0
        for i in range(h):
            ans = max(ans, max([hg[i][hi[i][j]] + vg[j][vi[j][i]]) for j in range(w)])
        return str(ans - 1)


if __name__ == '__main__':
    n, m = map(int, input().split())
    print(solve('{} {}\n'.format(n, m) + '\n'.join([input() for _ in range(n)])))