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 main():
    h,w = map(int, input().split())
    grid = []
    for i in range(h):
        s = list(input().rstrip())
        grid.append(s)
    l = [[0]*w for _ in range(h)]
    r = [[0]*w for _ in range(h)]
    d = [[0]*w for _ in range(h)]
    u = [[0]*w for _ in range(h)]
    for i in range(h):
        for j in range(w):
            if grid[i][j]!="#":
                if j==0:
                    l[i][j]=1
                    r[i][-(j+1)]=1
                else:
                    l[i][j]=l[i][j-1]+1
                    r[i][-(j+1)]=r[i][-(j)]
                    if j==w-1:
                      r[i][0]=r[i][1]+1
            if grid[i][-(w-j+1)]=="#":
                l[i][j]=0
                r[i][-(j+1)]=0
    for i in range(h):
        for j in range(w):
            if grid[i][j]!="#":
                if i==0:
                    d[i][j]=1
                    u[-(i+1)][j]=1
                else:
                    d[i][j]=d[i-1][j]+1
                    u[-(i+1)][j]=du[-(i)][j]+1
                    if i==h-1:
                      u[0][j] = u[1][j]
            if grid[i][j]=="#":
                d[i][j]=0
                u[-(i)][j]=0

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

    print(tmp)

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
def main():
    h, w = map(int, input().split())
    S = [input() for _ in range(h)]
    temp = [[0, 0] for _ in range(w*h)]
    for i in range(h):
        piyo = 0
        hoge = []
        for j in range(w):
            s = S[i][j]
            if s == ".":
                piyo += 1
                hoge.append(j)
            else:
                for k in hoge:
                    temp[i*h+k][0] = max(temp[i*h+k][0], piyo)
                piyo = 0
                hoge = []
        for k in hoge:
            temp[i*h+k][0]  = max(temp[i*h+k][0], piyo)
    for i in range(w):
        piyo = 0
        hoge = []
        for j in range(h):
            s = S[j][i]
            if s == ".":
                piyo += 1
                hoge.append(j)
            else:
                for k in hoge:
                    temp[k*h+i][1] = max(temp[k*h+i][1] , piyo)
                piyo = 0
                hoge = []
        for k in hoge:
            temp[k*h+i][1]  = max(temp[k*h+i][1] , piyo)
    result = sorted(temp, key = lambda x:x[0]+ x[1], reverse=True)[0]
    print(sum(result)-1)
main()

Submission status: Runtime Error

Solution code:
def main():
    import numpy as np
    h, w = map(int, input().split())
    S = [input() for _ in range(h)]
    hs = np.zeros(h,)
    ws = np.zeros(w,)
    for i in range(h):
        piyo = 0
        hoge = []
        for j in range(w):
            s = S[i][j]
            if s == ".":
                piyo += 1
                hoge.append(j)
            else:
                for k in hoge:
                    ws[k] = max(ws[k], piyo)
                piyo = 0
                hoge = []
        for k in hoge:
            ws[k] = max(ws[k], piyo)
    for i in range(w):
        piyo = 0
        hoge = []
        for j in range(h):
            s = S[j][i]
            if s == ".":
                piyo += 1
                hoge.append(j)
            else:
                for k in hoge:
                    hs[k] = max(hs[k], piyo)
                piyo = 0
                hoge = []
        for k in hoge:
            hs[k] = max(hs[k], piyo)   
    result = int(max(hs + ws-1))
    print(result)
main()

Submission status: Runtime Error

Solution code:
def main():
    import numpy as np
    h, w = map(int, input().split())
    S = [input() for _ in range(h)]
    hs = np.zeros(h,)
    ws = np.zeros(w,)
    for i in range(h):
        piyo = 0
        hoge = []
        for j in range(w):
            s = S[i][j]
            if s == ".":
                piyo += 1
                hoge.append(j)
            else:
                for k in hoge:
                    ws[k] = max(ws[k], piyo)
                piyo = 0
                hoge = []
        for k in hoge:
            ws[k] = max(ws[k], piyo)
    for i in range(w):
        piyo = 0
        hoge = []
        for j in range(h):
            s = S[j][i]
            if s == ".":
                piyo += 1
                hoge.append(j)
            else:
                for k in hoge:
                    hs[k] = max(hs[k], piyo)
                piyo = 0
                hoge = []
        for k in hoge:
            hs[k] = max(hs[k], piyo)   
    result = int(max(hs + ws-1))
    print(result)
main()

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3
import sys
try:
    from typing import List
except ImportError:
    pass


def solve(H: int, W: int, S: "List[str]"):
    d = [[0] * W for _ in range(H)]
    for y in range(H):
        x = 0
        while x < W:
            while x < W and S[y][x] == "#":
                x += 1
            xstt = x
            while x < W and S[y][x] == ".":
                x += 1
            xend = x
            for x2 in range(xstt, xend):
                d[y][x2] += xend - xstt
    for x in range(H):
        y = 0
        while y < H:
            while y < H and S[y][x] == "#":
                y += 1
            ystt = y
            while y < H and S[y][x] == ".":
                y += 1
            yend = y
            for y2 in range(ystt, yend):
                d[y2][x] += yend - ystt

    print(max(max(r) for r in d) - 1)


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    H = int(next(tokens))  # type: int
    W = int(next(tokens))  # type: int
    S = [next(tokens) for _ in range(H)]  # type: "List[str]"
    solve(H, W, S)


if __name__ == '__main__':
    main()

Submission status: Runtime Error

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

    left = [[-1]*W for _ in range(H)]
    right = [[-1]*W for _ in range(H)]
    up = [[N]*W for _ in range(H)]
    down = [[None]*W for _ in range(H)]

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

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

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

    for i in range(H):
        for j in range(W):
            if S[-1-i][-1-j] == '.':
                if i == 0:
                    down[-1-i][-1-j] = 0
                else:
                    down[-1-i][-1-j] = down[-1-(i-1)][-1-j] + 1
            
    ans = 0
    temp = [0] * W
    for i in range(H):
        for j in range(W):
            temp[j] = left[i][j] + right[i][j] + down[i][j] + up[i][j] + 1
        ans = max(ans, max(temp))
    print(ans)

main()

Submission status: Runtime Error

Solution code:
def main():
    left = [[None]*W]*H
    right = [[None]*W]*H
    up = [[None]*W]*H
    down = [[None]*W]*H

    for i in range(H):
        for j in range(W):
            if S[i][j] == '.':
                if j == 0:
                    left[i][j] = 0
                else:
                    left[i][j] = left[i][j-1] + 1
                if i == 0:
                    up[i][j] = 0
                else:
                    up[i][j] = up[i-1][j] + 1
            else:
                left[i][j] = -1
                up[i][j] = -1
            
            if S[-1-i][-1-j] == '.':
                if j == 0:
                    right[-1-i][-1-j] = 0
                else:
                    right[-1-i][-1-j] = right[-1-i][-1-(j-1)] + 1
                if i == 0:
                    down[-1-i][-1-j] = 0
                else:
                    down[-1-i][-1-j] = down[-1-(i-1)][-1-j] + 1
            else:
                right[-1-i][-1-j] = -1
                down[-1-i][-1-j] = -1

    ans = 0
    for i in range(H):
        for j in range(W):
            ans = max(ans, left[i][j]+right[i][j]+up[i][j]+down[i][j])
    print(ans+1)
    
main()

Submission status: Runtime Error

Solution code:
def main():
    H, W = map(int, input().split())
    S = [list(input()) for _ in range(H)]
    
    left = [[-1]*W]*H
    right = [[-1]*W]*H
    up = [[-1]*W]*H
    down = [[-1]*W]*H

    for i in range(H):
        for j in range(W):
            if S[i][j] == '.':
                if j == 0:
                    left[i][j] = 0
                else:
                    left[i][j] = left[i][j-1] + 1
                if i == 0:
                    up[i][j] = 0
                else:
                    up[i][j] = up[i-1][j] + 1
            else:
                left[i][j] = -1
                up[i][j] = -1
            
            if S[-1-i][-1-j] == '.':
                if j == 0:
                    right[-1-i][-1-j] = 0
                else:
                    right[-1-i][-1-j] = right[-1-i][-1-(j-1)] + 1
                if i == 0:
                    down[-1-i][-1-j] = 0
                else:
                    down[-1-i][-1-j] = down[-1-(i-1)][-1-j] + 1
            else:
                right[i][j] = -1
                down[i][j] = -1
                
    print(np.max(left+right+up+down) + 1)

main()

Submission status: Runtime Error

Solution code:
import numpy as np

def main():
    H, W = map(int, input().split())
    S = [list(input()) for _ in range(H)]
    
    left = np.zeros([H, W], dtype=np.int) - 1
    right = np.zeros([H, W], dtype=np.int) - 1
    up = np.zeros([H, W], dtype=np.int) - 1
    down = np.zeros([H, W], dtype=np.int) - 1

    for i in range(H):
        for j in range(W):
            if S[i][j] == '.':
                if j == 0:
                    left[i][j] = 0
                else:
                    left[i][j] = left[i][j-1] + 1
                if i == 0:
                    up[i][j] = 0
                else:
                    up[i][j] = up[i-1][j] + 1
            else:
                left[i][j] = -1
                up[i][j] = -1
            
            if S[-1-i][-1-j] == '.':
                if j == 0:
                    right[-1-i][-1-j] = 0
                else:
                    right[-1-i][-1-j] = right[-1-i][-1-(j-1)] + 1
                if i == 0:
                    down[-1-i][-1-j] = 0
                else:
                    down[-1-i][-1-j] = down[-1-(i-1)][-1-j] + 1
            else:
                right[i][j] = -1
                down[i][j] = -1
                
    print(np.max(left+right+up+down) + 1)

main()

Submission status: Runtime Error

Solution code:
import numpy as np
H,W=map(int,input().split(' '))
maze = [list(input()) for i in range(H)]
maze_w=[]
maze_h=[]
for i in maze:
    cnt = 0
    l = 0
    r = 0
    tmp = ''
    for j in i:
        if j != "#":
            cnt += 1
            r += 1
        elif cnt:
            tmp += str(cnt)*cnt+'0'
            l = r+1
            r = r+1
            cnt = 0
        else:
            tmp +='0'
    if cnt:
        tmp +=str(cnt)*cnt
    maze_w.append(list(tmp))

for i in range(W):
    cnt = 0
    h = 0
    t = 0
    tmp = ""
    for j in range(H):
        if maze[j][i]!='#':
            cnt += 1
            t +=1
        elif cnt:
            tmp += str(cnt)*cnt+'0'
            h = t+1
            t = t+1
            cnt = 0
        else:
            tmp += '0'
    if cnt:
        tmp += str(cnt)*cnt
    maze_h.append(list(tmp))
ans = 0
for i in range(H):
    for j in range(W):
        ans = max(ans,int(maze_h[j][i])+int(maze_w[i][j])-1)
print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np
H,W=map(int,input().split(' '))
maze = np.array([list(input()) for i in range(H)])
maze_w=[]
maze_h=np.array([['0']*W for i in range(H)])
for i in maze:
    cnt = 0
    l = 0
    r = 0
    tmp = ''
    for j in i:
        if j != "#":
            cnt += 1
            r += 1
        elif cnt:
            tmp += str(cnt)*cnt+'0'
            l = r+1
            r = r+1
            cnt = 0
        else:
            tmp +='0'
    if cnt:
        tmp +=str(cnt)*cnt
    maze_w.append(list(tmp))

for i in range(W):
    cnt = 0
    h = 0
    t = 0
    tmp = ""
    for j in maze[:,i]:
        if j!='#':
            cnt += 1
            t +=1
        elif cnt:
            tmp += str(cnt)*cnt+'0'
            h = t+1
            t = t+1
            cnt = 0
        else:
            tmp += '0'
    if cnt:
        tmp += str(cnt)*cnt
    maze_h[:,i] = list(tmp)
ans = 0
for i in range(H):
    for j in range(W):
        ans = max(ans,int(maze_h[i][j])+int(maze_w[i][j])-1)
print(ans)

Submission status: Runtime Error

Solution code:
#標準入力
H, W = map(int, input().split())
grid = []
for i in range(H):
    tmp = input()
    grid.append(tmp)

#グリッドの縦横を別々に調べる
import numpy as np
grid_int = np.zeros((H, W))
for i in range(H):
    count = 0
    for j in range(W):
        if grid[i][j] == '.':
            count += 1
            if j == W - 1:
                grid_int[i, j-count + 1:j + 1] = count
        elif grid[i][j] == '#':
            if j == 0:
                continue
            grid_int[i, j- count, j] = count
            count = 0


for j in range(W):
    count = 0
    for i in range(H):
        if grid[i][j] == '.':
            count += 1
            if i == H - 1:
                grid_int[i - count + 1: i + 1, j] += count
        elif grid[i][j] == '#':
            if i == 0:
                continue
            grid_int[i-count: i, j] += count
            count = 0

ans = 0
for i in range(H):
    tmp_max = max(grid_int[i]) - 1
    if ans < tmp_max:
        ans = tmp_max
print(int(ans))

Submission status: Runtime Error

Solution code:
#標準入力
H, W = map(int, input().split())
grid = []
for i in range(H):
    tmp = input()
    grid.append(tmp)

#グリッドの縦横を別々に調べる
import numpy as np
grid_int = np.zeros((H, W))
for i in range(H):
    count = 0
    for j in range(W):
        if grid[i][j] == '.':
            count += 1
            if j == W - 1:
                grid_int[i, j-count + 1:j + 1] = count
        elif grid[i][j] == '#':
            if j == 0:
                continue
            grid_int[i, j- count, j] = count
            count = 0


for j in range(W):
    count = 0
    for i in range(H):
        if grid[i][j] == '.':
            count += 1
            if i == H - 1:
                grid_int[i - count + 1, i + 1, j] += count
        elif grid[i][j] == '#':
            if i == 0:
                continue
            grid_int[i-count: i, j] += count
            count = 0

ans = 0
for i in range(H):
    tmp_max = max(grid_int[i]) - 1
    if ans < tmp_max:
        ans = tmp_max
print(int(ans))

Submission status: Runtime Error

Solution code:
#import sys
#input = sys.stdin.buffer.readline
import numpy as np

def main():
    H,W = map(int,input().split())
    S = np.array([list(input()) for _ in range(H)]) == '.' #'.'に一致するならTrueしなければFalse

    up = np.zeros((H,W), dtype=int)
    down = np.zeros((H,W), dtype=int)
    left = np.zeros((H,W), dtype=int)
    right = np.zeros((H,W), dtype=int)
    
    for i in range(H-1):
        up[i+1,:] = (up[i,:] + 1) * S[i,:] #npの変数名[k,l]でk行l列を取り出す
    for i in range(H-1):                   #:なら全部をそれぞれについて見ていく
        down[H - 2 - i,:] = (down[H - 1 - i,:] + 1) * S[H - 1 - i,:]
    for i in range(W-1):
        left[:,i+1] = (left[:,i] + 1) * S[:,i]
    for i in range(W-1):
        right[:,H - 2 - i] = (right[:,H - 1 - i] + 1) * S[:,H - 1 - i]
        
    print(((up+down+left+right)*S).max()+1) #カケザンデ要素ごとの掛け算可能
    
if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:

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

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)

# print(tate)

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

Solution code:
import numpy as np

H, W = map(int, input().split())
A = []
for _ in range(H):
    S = [0 if c == '#' else 1 for c in input().strip()]
    A.append(S)
A = np.array(A)
top = np.zeros((H+1, W), dtype=np.int)
bottom = np.zeros((H+1, W), dtype=np.int)
right = np.zeros((H, W+1), dtype=np.int)
left = np.zeros((H, W+1), dtype=np.int)
for i in range(1, H+1):
    top[i] = (top[i-1] + 1) * A[i-1]
for i in range(H-1, -1, -1):
    bottom[i] = (bottom[i+1] + 1) * A[i]
for i in range(1, W+1):
    right[:, i] = (right[:, i-1] + 1) * A[:, i-1]
for i in range(W-1, -1, -1):
    left[:, i] = (left[:, i+1] + 1) * A[:, i]
R = (top[1:] + bottom[:H] - 1) * A
C = (right[:, 1:] + left[:, :W] - 1) * A
RC = (R + C - 1) * A

print(RC.max)

Submission status: Runtime Error

Solution code:
#標準入力
H, W = map(int, input().split())
grid = []
for i in range(H):
    tmp = input()
    grid.append(tmp)

#グリッドの縦横を別々に調べる
import NumPy as np
grid_int = np.zeros(H, W)
for i in range(H):
    count = 0
    for j in range(W):
        if grid[i][j] == '.':
            count += 1
            if j == W - 1:
                for l in range(count):
                    grid_int[i][j-l] = count
        elif grid[i][j] == '#':
            if j == 0:
                continue
            for k in range(count):
                grid_int[i][j- k - 1] = count
            count = 0


for j in range(W):
    count = 0
    for i in range(H):
        if grid[i][j] == '.':
            count += 1
            if i == H - 1:
                for m in range(count):
                    grid_int[i - m][j] += count
        elif grid[i][j] == '#':
            if i == 0:
                continue
            for k in range(count):
                grid_int[i-k-1][j] += count
            count = 0

ans = 0
for i in range(H):
    tmp_max = max(grid_int[i]) - 1
    if ans < tmp_max:
        ans = tmp_max
print(ans)

Submission status: Runtime Error

Solution code:
#標準入力
H, W = map(int, input().split())
grid = []
for i in range(H):
    tmp = input()
    grid.append(tmp)

#グリッドの縦横を別々に調べる
import numpy as np
grid_int = np.zeros(H, W)
for i in range(H):
    count = 0
    for j in range(W):
        if grid[i][j] == '.':
            count += 1
            if j == W - 1:
                for l in range(count):
                    grid_int[i][j-l] = count
        elif grid[i][j] == '#':
            if j == 0:
                continue
            for k in range(count):
                grid_int[i][j- k - 1] = count
            count = 0


for j in range(W):
    count = 0
    for i in range(H):
        if grid[i][j] == '.':
            count += 1
            if i == H - 1:
                for m in range(count):
                    grid_int[i - m][j] += count
        elif grid[i][j] == '#':
            if i == 0:
                continue
            for k in range(count):
                grid_int[i-k-1][j] += count
            count = 0

ans = 0
for i in range(H):
    tmp_max = max(grid_int[i]) - 1
    if ans < tmp_max:
        ans = tmp_max
print(ans)

Submission status: Runtime Error

Solution code:
#標準入力
H, W = map(int, input().split())
grid = []
for i in range(H):
    tmp = input()
    grid.append(tmp)

#グリッドの縦横を別々に調べる
import numpy
grid_int = [[0] * W for i in range(H)]
grid_int = np.array(grid_int)
for i in range(H):
    count = 0
    for j in range(W):
        if grid[i][j] == '.':
            count += 1
            if j == W - 1:
                for l in range(count):
                    grid_int[i][j-l] = count
        elif grid[i][j] == '#':
            if j == 0:
                continue
            for k in range(count):
                grid_int[i][j- k - 1] = count
            count = 0


for j in range(W):
    count = 0
    for i in range(H):
        if grid[i][j] == '.':
            count += 1
            if i == H - 1:
                for m in range(count):
                    grid_int[i - m][j] += count
        elif grid[i][j] == '#':
            if i == 0:
                continue
            for k in range(count):
                grid_int[i-k-1][j] += count
            count = 0

ans = 0
for i in range(H):
    tmp_max = max(grid_int[i]) - 1
    if ans < tmp_max:
        ans = tmp_max
print(ans)

Submission status: Runtime Error

Solution code:
# D - Lamp

H, W = map(int, input().split())
M = [[str(m) for m in input()] for _ in range(H)]
U = [[0] * W for _ in range(H)]
L = [[0] * W for _ in range(H)]
D = [[0] * W for _ in range(H)]
R = [[0] * W for _ in range(H)]
for i in range(H):
    for j in range(W):
        if i == 0 and M[i][j] != '#':
            U[i][j] = 1
        if j == 0 and M[i][j] != '#':
            L[i][j] = 1
        if i != 0 and j != 0 and M[i][j] != '#':
            U[i][j] = U[i - 1][j] + 1
            L[i][j] = L[i][j - 1] + 1

for i in reversed(range(H)):
    for j in reversed(range(W)):
        if i == H - 1 and M[i][j] != '#':
            D[i][j] = 1
        if j == W - 1 and M[i][j] != '#':
            R[i][j] = 1
        if i != H - 1 and j != W - 1 and M[i][j] != '#':
            D[i][j] = D[i + 1][j] + 1
            R[i][j] = R[i][j + 1] + 1

mx = 0
for i in range(H):
    for j in range(H):
        p = U[i][j] + L[i][j] + D[i][j] + R[i][j] - 3
        mx = max(mx, p)

print(mx)

Submission status: Runtime Error

Solution code:
h,w = map(int,input().split())
li  = list(list(input()) for i in range(h))
sc  = [[0]*w for j in range(h)]
ans = 0

def chk_l(y,x,score):
  if x==0:
    return score
  
  if li[y][x-1]=='.':
    score += 1
    return chk_l(y,x-1,score)
  else:
    return score

def chk_r(y,x,w,score):
  if x==w-1:
    return score

  if li[y][x+1]=='.':
    score += 1
    return chk_r(y,x+1,w,score)
  else:
    return score

def chk_t(y,x,score):
  if y==0:
    return score
  
  if li[y-1][x]=='.':
    score += 1
    return chk_t(y-1,x,score)
  else:
    return score

def chk_b(y,x,h,score):
  if y==h-1:
    return score
  
  if li[y+1][x]=='.':
    score += 1
    return chk_b(y+1,x,h,score)
  else:
    return score

for y in range(h):
  for x in range(w):
    if li[y][x]=='#':
      continue
    score = 1
    score = chk_l(y,x,score)
    score = chk_r(y,x,w,score)
    score = chk_t(y,x,score)
    score = chk_b(y,x,h,score)
    sc[y][x] = score

for y in range(h):
  for x in range(w):
    ans = max(ans,sc[y][x])

print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np
h,w=map(int,input().split())
S=np.array([list(input()) for _ in range(h)])
S=np.where(S==".",1,0)

left,right,up,down=[np.zeros((h,w)) for _ in range(4)]
for i in range(w):
    left[:,i]=(left[:,i-1]+1)*S[:,i]
    right[:,-i-1]=(right[:,-i]+1)*S[:,-i-1]
for i in range(h):
    up[i]=(up[i-1]+1)*S[i]
    down[-i-1]=(down[-i]+1)*S[-i-1]

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

Submission status: Runtime Error

Solution code:
def lightdot(px, py):
    dx = [1, 0, -1, 0]
    dy = [0, 1, 0, -1]
    # それぞれ上、下、左、右に移動していく
    pos = deque([[px, py, 0, 0], [px, py, 1, 0], [px, py, 2, 0], [px, py, 3, 0]])
    res = 0

    while len(pos) > 0:
        x, y, direct, depth = pos.popleft()
        nx = x + dx[direct]
        ny = y + dy[direct]
        if 0 <= nx < w and 0 <= ny < h and maze[ny][nx] == '.':
            # 方向は引き継ぐ
            pos.append([nx, ny, direct, depth + 1])
        else:
            res += depth
    # 現在地点の'.'も含める
    return res + 1

for i in range(w):
    for j in range(h):
        if maze[j][i] == '.':
            ans = max(ans, lightdot(i, j))
print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np 
H, W = map(int, input().split())
grid = []
for _ in range(H):
    grid.append([s for s in input()])

yoko = [[0 for _ in range(W)] for _ in range(H)]
tate =  [[0 for _ in range(W)] for _ in range(H)]

for h in range(H):
    cnt = 0
    for w in range(W):
        if grid[h][w] == ".":
            cnt += 1
        else:
            cnt = 0
        yoko[h][w] = cnt

for w in range(W):
    cnt = 0
    for h in range(H):
        if grid[h][w] == ".":
            cnt += 1
        else:
            cnt = 0
        tate[h][w] = cnt

tate = np.array(tate)
yoko = np.array(yoko)

for h in range(H):
    my_max = 0
    for w in range(W):
        if yoko[h][W - 1 - w] != 0:
            my_max = max(my_max, yoko[h][W - 1 - w])
            yoko[h][W - 1 - w] = my_max
        else:
            my_max = 0

tate = tate.T

for h in range(W):
    my_max = 0
    for w in range(H):
        if tate[h][H - 1 - w] != 0:
            my_max = max(my_max, tate[h][H - 1 - w])
            tate[h][H - 1 - w] = my_max
        else:
            my_max = 0
            
tate = tate.T
ans = tate + yoko - 1

print(np.max(ans.ravel()))

Submission status: Runtime Error

Solution code:
import numpy as np 
H, W = map(int, input().split())
grid = []
for _ in range(H):
    grid.append([s for s in input()])

yoko = [[0 for _ in range(W)] for _ in range(H)]
tate =  [[0 for _ in range(W)] for _ in range(H)]

for h in range(H):
    cnt = 0
    for w in range(W):
        if grid[h][w] == ".":
            cnt += 1
        else:
            cnt = 0
        yoko[h][w] = cnt

for w in range(W):
    cnt = 0
    for h in range(H):
        if grid[h][w] == ".":
            cnt += 1
        else:
            cnt = 0
        tate[h][w] = cnt

tate = np.array(tate)
yoko = np.array(yoko)

for h in range(H):
    my_max = 0
    for w in range(W):
        if yoko[h][W - 1 - w] != 0:
            my_max = max(my_max, yoko[h][W - 1 - w])
            yoko[h][W - 1 - w] = my_max
        else:
            my_max = 0

tate = tate.T

for h in range(W):
    my_max = 0
    for w in range(H):
        if tate[h][H - 1 - w] != 0:
            my_max = max(my_max, tate[h][H - 1 - w])
            tate[h][H - 1 - w] = my_max
        else:
            my_max = 0
            
tate = tate.T

ans = -10000
for h in range(H):
    for w in range(W):
        ans = max(ans, tate[w][h] + yoko[w][h] - 1)
print(ans)

Submission status: Runtime Error

Solution code:
h, w = map(int, input().split())

S = [input() for i in range(h)]

light = 0

for i in range(h):
    for j in range(w):
        if S[i][j] != "#":
            cnt = 0
            if j < w-1:
                for k in range(j+1,w):
                    if S[i][k] != "#":
                        cnt += 1
                    else:
                        break
            if j > 0:
                for k in range(j-1)[::-1]:
                    if S[i][k] != "#":
                        cnt += 1
                    else:
                        break
            if i < h-1:
                for k in range(i+1,h):
                    if S[i][k] != "#":
                        cnt += 1
                    else:
                        break
            if i > 0:
                for k in range(j-1)[::-1]:
                    if S[i][k] != "#":
                        cnt += 1
                    else:
                        break
            light = max(light, cnt)
        else:
            continue

print(light)

Submission status: Runtime Error

Solution code:
h,w=map(int,input().split())
M=[]
r=[]
for i in range(h):
  M.append(input())
ans=np.zeros((2, w, h), dtype=np.int) - 1
max=0
for i in range(h):
  for j in range(w):
    if M[i][j]=='#':
      continue
    else:
      temp=1
      if ans[i][j][0]==-1:
        for k in range(i+1,h):
          if M[k][j]=='.':
            temp+=1
          else:
            break
        for k in range(i,i+temp):
          ans[k][j][0]=temp
      if ans[i][j][1]==-1:
        temp=1
        for k in range(j+1,w):
          if M[i][k]=='.':
            temp+=1
          else:
            break
        for k in range(j,j+temp):
          ans[i][k][1]=temp
      if ans[i][j][0]+ans[i][j][1]-1>max:
        max=ans[i][j][0]+ans[i][j][1]-1
print(max)