Problem:


Score : 400 points

Problem Statement

There is a grid with H horizontal rows and W vertical columns, and there are obstacles on some of the squares.

Snuke is going to choose one of the squares not occupied by an obstacle and place a lamp on it.
The lamp placed on the square will emit straight beams of light in four cardinal directions: up, down, left, and right.
In each direction, the beam will continue traveling until it hits a square occupied by an obstacle or it hits the border of the grid. It will light all the squares on the way, including the square on which the lamp is placed, but not the square occupied by an obstacle.

Snuke wants to maximize the number of squares lighted by the lamp.

You are given H strings S_i (1 \leq i \leq H), each of length W. If the j-th character (1 \leq j \leq W) of S_i is #, there is an obstacle on the square at the i-th row from the top and the j-th column from the left; if that character is ., there is no obstacle on that square.

Find the maximum possible number of squares lighted by the lamp.

Constraints

1 \leq H \leq 2,000

1 \leq W \leq 2,000

S_i is a string of length W consisting of # and ..

. occurs at least once in one of the strings S_i (1 \leq i \leq H).

Input

Input is given from Standard Input in the following format:

H W
S_1
:
S_H

Output

Print the maximum possible number of squares lighted by the lamp.

Sample Input 1

4 6
#..#..
.....#
....#.
#.#...

Sample Output 1

8

If Snuke places the lamp on the square at the second row from the top and the second column from the left, it will light the following squares: the first through fifth squares from the left in the second row, and the first through fourth squares from the top in the second column, for a total of eight squares.

Sample Input 2

8 8
..#...#.
....#...
##......
..###..#
...#..#.
##....#.
#...#...
###.#..#

Sample Output 2

13



Sample input:
4 6
#..#..
.....#
....#.
#.#...


Sample output:
8

Submission status: Runtime Error

Solution code:
H, W = map(int, input().split())
s, ans = [], 0
# dpr, dpl, dpd, dpu = {},{},{},{}
#dpr, dpl, dpd, dpu = [0]*W,[0]*W,[0]*H,[0]*H
#dpr, dpl, dpd, dpu = [None]*W,[None]*W,[None]*H,[None]*H
dpr = [[None] * W for _ in range(W)]
dpl = [[None] * W for _ in range(W)]
dpd = [[None] * W for _ in range(W)]
dpu = [[None] * W for _ in range(W)]

for i in range(H):
    s.append(input())

def getCount(h, w):
    if s[h][w] == '#':
        return 0
    rcnt, lcnt, dcnt, ucnt = 0,0,0,0

    # to right
    for i in range(w+1, W):
        key = str(h) + str(i)
        if s[h][i] == '.':
            if dpr[h][i] is not None:
                rcnt += dpr[h][i] + 1
                break
            else:
                rcnt += 1
        else:
            break
    dpr[h][w] = rcnt

    # to left
    for i in reversed(range(w)):
        key = str(h) + str(i)
        if s[h][i] == '.':
            if dpl[h][i] is not None:
                lcnt += dpl[h][i] + 1
                break
            else:
                lcnt += 1
        else:
            break
    dpl[h][w] = lcnt

    # to down
    for i in range(h+1, H):
        key = str(i) + str(w)
        if s[i][w] == '.':
            if dpr[i][w] is not None:
                dcnt += dpd[i][w] + 1
                break
            else:
                dcnt += 1
        else:
            break
    dpd[h][w] = dcnt

    # to up
    for i in reversed(range(h)):
        key = str(i) + str(w)
        if s[i][w] == '.':
            if dpr[i][w] is not None:
                ucnt += dpu[i][w] + 1
                break
            else:
                ucnt += 1
        else:
            break
    dpu[h][w] = ucnt

    return rcnt + lcnt + dcnt + ucnt + 1

for i in range(H):
    for j in range(W):
        ans = max(ans, getCount(i, j))

print(ans)

Submission status: Runtime Error

Solution code:
H, W = map(int, input().split())
s, ans = [], 0
# dpr, dpl, dpd, dpu = {},{},{},{}
#dpr, dpl, dpd, dpu = [0]*W,[0]*W,[0]*H,[0]*H
#dpr, dpl, dpd, dpu = [None]*W,[None]*W,[None]*H,[None]*H
dpr = [[None] * W for _ in range(W)]
dpl = [[None] * W for _ in range(W)]
dpd = [[None] * W for _ in range(W)]
dpu = [[None] * W for _ in range(W)]

for i in range(H):
    s.append(input())

def getCount(h, w):
    if s[h][w] == '#':
        return 0
    rcnt, lcnt, dcnt, ucnt = 0,0,0,0

    # to right
    for i in range(w+1, W):
        key = str(h) + str(i)
        if s[h][i] == '.':
            if dpr[h][i] is not None:
                rcnt += dpr[h][i] + 1
                break
            else:
                rcnt += 1
        else:
            break
    dpr[h][w] = rcnt

    # to left
    for i in reversed(range(w)):
        key = str(h) + str(i)
        if s[h][i] == '.':
            if dpl[h][i] is not None:
                lcnt += dpl[h][i] + 1
                break
            else:
                lcnt += 1
        else:
            break
    dpl[h][w] = lcnt

    # to down
    for i in range(h+1, H):
        key = str(i) + str(w)
        if s[i][w] == '.':
            if dpr[i][w] is not None:
                dcnt += dpd[i][w] + 1
                break
            else:
                dcnt += 1
        else:
            break
    dpd[h][w] = dcnt

    # to up
    for i in reversed(range(h)):
        key = str(i) + str(w)
        if s[i][w] == '.':
            if dpr[i][w] is not None:
                ucnt += dpu[i][w] + 1
                break
            if key in dpu:
                ucnt += dpu[key] + 1
                break
            else:
                ucnt += 1
        else:
            break
    dpu[h][w] = ucnt

    return rcnt + lcnt + dcnt + ucnt + 1

for i in range(H):
    for j in range(W):
        ans = max(ans, getCount(i, j))

print(ans)

Submission status: Runtime Error

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

U=[[-1]*W for _ in range(H)]
D=[[-1]*W for _ in range(H)]
L=[[-1]*W for _ in range(H)]
R=[[-1]*W for _ in range(H)]

def u(i,j):
    if U[i][j]==-1:
        if S[i][j]=='#':
            U[i][j]==-2
        elif i==0:
            U[i][j]=0
        elif U[i-1][j]==-1:
            u(i-1,j)
            if U[i-1][j]==-2:
                U[i][j]=0
            else:
                U[i][j]=U[i-1][j]+1
        elif U[i-1][j]==-2:
            U[i][j]=0
        else:
            U[i][j]=U[i-1][j]+1

def d(i,j):
    if D[i][j]==-1:
        if S[i][j]=='#':
            D[i][j]==-2
        elif i==H-1:
            D[i][j]=0
        elif D[i+1][j]==-1:
            d(i+1,j)
            if D[i+1][j]==-2:
                D[i][j]=0
            else:
                D[i][j]=D[i+1][j]+1
        elif D[i+1][j]==-2:
            D[i][j]=0
        else:
            D[i][j]=D[i+1][j]+1

def l(i,j):
    if L[i][j]==-1:
        if S[i][j]=='#':
            L[i][j]==-2
        elif j==0:
            L[i][j]=0
        elif L[i][j-1]==-1:
            l(i,j-1)
            if L[i][j-1]==-2:
                L[i][j]=0
            else:
                L[i][j]=L[i][j-1]+1
        elif L[i][j-1]==-2:
            L[i][j]=0
        else:
            L[i][j]=L[i][j-1]+1

def r(i,j):
    if R[i][j]==-1:
        if S[i][j]=='#':
            R[i][j]==-2
        elif j==W-1:
            R[i][j]=0
        elif R[i][j+1]==-1:
            r(i,j+1)
            if R[i][j+1]==-2:
                R[i][j]=0
            else:
                R[i][j]=R[i][j+1]+1
        elif R[i][j+1]==-2:
            R[i][j]=0
        else:
            R[i][j]=R[i][j+1]+1

def udlr(i,j):
    if S[i][j]=='#':
        U[i][j]=D[i][j]=L[i][j]=R[i][j]=-2
        return 0
    else:
        u(i,j);d(i,j);l(i,j);r(i,j);
        return U[i][j]+D[i][j]+L[i][j]+R[i][j]+1

x=0
for i in range(H):
    for j in range(W):
        x=max(x,max(x,udlr(i,j)))
print(x)

Submission status: Runtime Error

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

U=[[-1]*W for _ in range(H)]
D=[[-1]*W for _ in range(H)]
L=[[-1]*W for _ in range(H)]
R=[[-1]*W for _ in range(H)]

def u(i,j):
    if U[i][j]==-1:
        if S[i][j]=='#':
            U[i][j]==-2
        elif i==0:
            U[i][j]=0
        elif U[i-1][j]==-1:
            u(i-1,j)
            if U[i-1][j]==-2:
                U[i][j]=0
            else:
                U[i][j]=U[i-1][j]+1
        elif U[i-1][j]==-2:
            U[i][j]=0
        else:
            U[i][j]=U[i-1][j]+1

def d(i,j):
    if D[i][j]==-1:
        if S[i][j]=='#':
            D[i][j]==-2
        elif i==H-1:
            D[i][j]=0
        elif D[i+1][j]==-1:
            d(i+1,j)
            if D[i+1][j]==-2:
                D[i][j]=0
            else:
                D[i][j]=D[i+1][j]+1
        elif D[i+1][j]==-2:
            D[i][j]=0
        else:
            D[i][j]=D[i+1][j]+1

def l(i,j):
    if L[i][j]==-1:
        if S[i][j]=='#':
            L[i][j]==-2
        elif j==0:
            L[i][j]=0
        elif L[i][j-1]==-1:
            l(i,j-1)
            if L[i][j-1]==-2:
                L[i][j]=0
            else:
                L[i][j]=L[i][j-1]+1
        elif L[i][j-1]==-2:
            L[i][j]=0
        else:
            L[i][j]=L[i][j-1]+1

def r(i,j):
    if R[i][j]==-1:
        if S[i][j]=='#':
            R[i][j]==-2
        elif j==W-1:
            R[i][j]=0
        elif R[i][j+1]==-1:
            r(i,j+1)
            if R[i][j+1]==-2:
                R[i][j]=0
            else:
                R[i][j]=R[i][j+1]+1
        elif R[i][j+1]==-2:
            R[i][j]=0
        else:
            R[i][j]=R[i][j+1]+1

def udlr(i,j):
    if S[i][j]=='#':
        U[i][j]=D[i][j]=L[i][j]=R[i][j]=-2
        return 0
    else:
        if U[i][j]==-1:
            u(i,j)
        if D[i][j]==-1:
            d(i,j)
        if L[i][j]==-1:
            l(i,j)
        if R[i][j]==-1:
            r(i,j)
        return U[i][j]+D[i][j]+L[i][j]+R[i][j]+1

x=0
for i in range(H):
    for j in range(W):
        x=max(x,max(x,udlr(i,j)))
print(x)

Submission status: Runtime Error

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

U=[[-1]*W for _ in range(H)]
D=[[-1]*W for _ in range(H)]
L=[[-1]*W for _ in range(H)]
R=[[-1]*W for _ in range(H)]

def u(i,j):
    if U[i][j]==-1 or U[i][j]==-2:
        if S[i][j]=='#':
            U[i][j]==-2
        elif i==0:
            U[i][j]=0
        elif U[i-1][j]==-1:
            u(i-1,j)
            if U[i-1][j]==-2:
                U[i][j]=0
            else:
                U[i][j]=U[i-1][j]+1
        elif U[i-1][j]==-2:
            U[i][j]=0
        else:
            U[i][j]=U[i-1][j]+1

def d(i,j):
    if D[i][j]==-1 or D[i][j]==-2:
        if S[i][j]=='#':
            D[i][j]==-2
        elif i==H-1:
            D[i][j]=0
        elif D[i+1][j]==-1:
            d(i+1,j)
            if D[i+1][j]==-2:
                D[i][j]=0
            else:
                D[i][j]=D[i+1][j]+1
        elif D[i+1][j]==-2:
            D[i][j]=0
        else:
            D[i][j]=D[i+1][j]+1

def l(i,j):
    if L[i][j]==-1 or L[i][j]==-2:
        if S[i][j]=='#':
            L[i][j]==-2
        elif j==0:
            L[i][j]=0
        elif L[i][j-1]==-1:
            l(i,j-1)
            if L[i][j-1]==-2:
                L[i][j]=0
            else:
                L[i][j]=L[i][j-1]+1
        elif L[i][j-1]==-2:
            L[i][j]=0
        else:
            L[i][j]=L[i][j-1]+1

def r(i,j):
    if R[i][j]==-1 or R[i][j]==-2:
        if S[i][j]=='#':
            R[i][j]==-2
        elif j==W-1:
            R[i][j]=0
        elif R[i][j+1]==-1:
            r(i,j+1)
            if R[i][j+1]==-2:
                R[i][j]=0
            else:
                R[i][j]=R[i][j+1]+1
        elif R[i][j+1]==-2:
            R[i][j]=0
        else:
            R[i][j]=R[i][j+1]+1

def udlr(i,j):
    if S[i][j]=='#':
        U[i][j]=D[i][j]=L[i][j]=R[i][j]=-2
        return 0
    else:
        if U[i][j]==-1:
            u(i,j)
        if D[i][j]==-1:
            d(i,j)
        if L[i][j]==-1:
            l(i,j)
        if R[i][j]==-1:
            r(i,j)
        return U[i][j]+D[i][j]+L[i][j]+R[i][j]+1

x=0
for i in range(H):
    for j in range(W):
        x=max(x,max(x,udlr(i,j)))
print(x)

Submission status: Runtime Error

Solution code:
H,W=map(int, input().split())
S=[input() for _ in range(H)]
 
U=[[-1]*W for _ in range(H)]
D=[[-1]*W for _ in range(H)]
L=[[-1]*W for _ in range(H)]
R=[[-1]*W for _ in range(H)]
 
def u(i,j):
    if S[i][j]=='#':
        U[i][j]==-2
    elif i==0:
        U[i][j]=0
    elif U[i-1][j]==-1:
        u(i-1,j)
        if U[i-1][j]==-2:
            U[i][j]=0
        else:
            U[i][j]=U[i-1][j]+1
    elif U[i-1][j]==-2:
        U[i][j]=0
    else:
        U[i][j]=U[i-1][j]+1
 
def d(i,j):
    if S[i][j]=='#':
        D[i][j]==-2
    elif i==H-1:
        D[i][j]=0
    elif D[i+1][j]==-1:
        d(i+1,j)
        if D[i+1][j]==-2:
            D[i][j]=0
        else:
            D[i][j]=D[i+1][j]+1
    elif D[i+1][j]==-2:
        D[i][j]=0
    else:
        D[i][j]=D[i+1][j]+1
 
def l(i,j):
    if S[i][j]=='#':
        L[i][j]==-2
    elif j==0:
        L[i][j]=0
    elif L[i][j-1]==-1:
        l(i,j-1)
        if L[i][j-1]==-2:
            L[i][j]=0
        else:
            L[i][j]=L[i][j-1]+1
    elif L[i][j-1]==-2:
        L[i][j]=0
    else:
        L[i][j]=L[i][j-1]+1
 
def r(i,j):
    if S[i][j]=='#':
        R[i][j]==-2
    elif j==W-1:
        R[i][j]=0
    elif R[i][j+1]==-1:
        r(i,j+1)
        if R[i][j+1]==-2:
            R[i][j]=0
        else:
            R[i][j]=R[i][j+1]+1
    elif R[i][j+1]==-2:
        R[i][j]=0
    else:
        R[i][j]=R[i][j+1]+1
 
def udlr(i,j):
    if S[i][j]=='#':
        U[i][j]=D[i][j]=L[i][j]=R[i][j]=-2
        return 0
    else:
        if U[i][j]==-1:
            u(i,j)
        if D[i][j]==-1:
            d(i,j)
        if L[i][j]==-1:
            l(i,j)
        if R[i][j]==-1:
            r(i,j)
        return U[i][j]+D[i][j]+L[i][j]+R[i][j]+1
 
x=0
for i in range(H):
    for j in range(W):
        x=max(x,max(x,udlr(i,j)))
print(x)

Submission status: Runtime Error

Solution code:
import numpy as np
import sys
buf = sys.stdin.buffer

H, W = map(int, buf.readline().split())
grid = np.zeros((H + 2, W + 2), np.int32)
grid[1:-1, 1:-1] = np.where(np.array(list(map(list, buf.read().decode('utf-8').split()))).reshape(H, W) == '.', 1, 0)
grid_v = grid.T

right = np.maximum.accumulate(np.where(grid < 1, np.arange(W + 2), 0), axis=1)
left = np.flip(np.minimum.accumulate(np.flip(np.where(grid < 1, np.arange(W + 2), 10 ** 10), axis=1), axis=1), axis=1)
down = np.maximum.accumulate(np.where(grid_v < 1, np.arange(H + 2), 0), axis=1).T
up = np.flip(np.minimum.accumulate(np.flip(np.where(grid_v < 1, np.arange(H + 2), 10 ** 10), axis=1), axis=1), axis=1).T

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

Submission status: Runtime Error

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

U=[[-1]*W for _ in range(H)]
D=[[-1]*W for _ in range(H)]
L=[[-1]*W for _ in range(H)]
R=[[-1]*W for _ in range(H)]

def u(i,j):
    if S[i][j]=='#':
        U[i][j]==-2
    elif i==0:
        U[i][j]=0
    elif U[i-1][j]==-1:
        u(i-1,j)
        if U[i-1][j]==-2:
            U[i][j]=0
        else:
            U[i][j]=U[i-1][j]+1
    elif U[i-1][j]==-2:
        U[i][j]=0
    else:
        U[i][j]=U[i-1][j]+1

def d(i,j):
    if S[i][j]=='#':
        D[i][j]==-2
    elif i==H-1:
        D[i][j]=0
    elif D[i+1][j]==-1:
        d(i+1,j)
        if D[i+1][j]==-2:
            D[i][j]=0
        else:
            D[i][j]=D[i+1][j]+1
    elif D[i+1][j]==-2:
        D[i][j]=0
    else:
        D[i][j]=D[i+1][j]+1

def l(i,j):
    if S[i][j]=='#':
        L[i][j]==-2
    elif j==0:
        L[i][j]=0
    elif L[i][j-1]==-1:
        l(i,j-1)
        if L[i][j-1]==-2:
            L[i][j]=0
        else:
            L[i][j]=L[i][j-1]+1
    elif L[i][j-1]==-2:
        L[i][j]=0
    else:
        L[i][j]=L[i][j-1]+1

def r(i,j):
    if S[i][j]=='#':
        R[i][j]==-2
    elif j==W-1:
        R[i][j]=0
    elif R[i][j+1]==-1:
        r(i,j+1)
        if R[i][j+1]==-2:
            R[i][j]=0
        else:
            R[i][j]=R[i][j+1]+1
    elif R[i][j+1]==-2:
        R[i][j]=0
    else:
        R[i][j]=R[i][j+1]+1

def udlr(i,j):
    if S[i][j]=='#':
        U[i][j]=D[i][j]=L[i][j]=R[i][j]=-2
        return 0
    else:
        if U[i][j]==-1:
            u(i,j)
        if D[i][j]==-1:
            d(i,j)
        if L[i][j]==-1:
            l(i,j)
        if R[i][j]==-1:
            r(i,j)
        return U[i][j]+D[i][j]+L[i][j]+R[i][j]+1

x=0
for i in range(H):
    for j in range(W):
        x=max(x,max(x,udlr(i,j)))
print(x)

Submission status: Runtime Error

Solution code:
import sys

sys.setrecursionlimit(1000000000000)
H, W = map(int, input().split())
s, dp, ans = [], {}, 0
for i in range(H):
    s.append(input())
def getRightCount(h, w):
    key = str(h) + str(w) + 'r'
    if key in dp:
        return dp[key]
    elif s[h][w] == '#':
        dp[key] = 0
    elif w == W - 1:
        dp[key] = 0
    elif s[h][w+1] == '#':
        dp[key] = 0
    else:
        dp[key] = 1 + getRightCount(h, w+1)
    return dp[key]
def getLeftCount(h, w):
    key = str(h) + str(w) + 'l'
    if key in dp:
        return dp[key]
    elif s[h][w] == '#':
        dp[key] = 0
    elif w == 0:
        dp[key] = 0
    elif s[h][w-1] == '#':
        dp[key] = 0
    else:
        dp[key] = 1 + getLeftCount(h, w-1)
    return dp[key]
def getDownCount(h, w):
    key = str(h) + str(w) + 'd'
    if key in dp:
        return dp[key]
    elif s[h][w] == '#':
        dp[key] = 0
    elif h == H - 1:
        dp[key] = 0
    elif s[h+1][w] == '#':
        dp[key] = 0
    else:
        dp[key] = 1 + getDownCount(h+1, w)
    return dp[key]
def getUpCount(h, w):
    key = str(h) + str(w) + 'u'
    if key in dp:
        return dp[key]
    elif s[h][w] == '#':
        dp[key] = 0
    elif h == 0:
        dp[key] = 0
    elif s[h-1][w] == '#':
        dp[key] = 0
    else:
        dp[key] = 1 + getUpCount(h-1, w)
    return dp[key]
def getCount(h, w):
    if s[h][w] == '#':
        return 0
    rCnt, lCnt, uCnt, dCnt = 0,0,0,0
    key = str(h) + str(w)
    # to right
    rkey = key + 'r'
    rCnt = getRightCount(h, w)
    # to left
    lkey = key + 'l'
    lCnt = getLeftCount(h, w)
    # to down
    dkey = key + 'd'
    dCnt = getDownCount(h, w)
    # to up
    ukey = key + 'u'
    uCnt = getUpCount(h, w)
    return rCnt + lCnt + uCnt + dCnt + 1

for i in reversed(range(H)):
    for j in reversed(range(W)):
        ans = max(ans, getCount(i, j))
print(ans)

Submission status: Runtime Error

Solution code:
H, W = map(int, input().split())
s, dp, ans = [], {}, 0
for i in range(H):
    s.append(input())
def getRightCount(h, w):
    key = str(h) + str(w) + 'r'
    if key in dp:
        return dp[key]
    elif s[h][w] == '#':
        dp[key] = 0
    elif w == W - 1:
        dp[key] = 0
    elif s[h][w+1] == '#':
        dp[key] = 0
    else:
        dp[key] = 1 + getRightCount(h, w+1)
    return dp[key]
def getLeftCount(h, w):
    key = str(h) + str(w) + 'l'
    if key in dp:
        return dp[key]
    elif s[h][w] == '#':
        dp[key] = 0
    elif w == 0:
        dp[key] = 0
    elif s[h][w-1] == '#':
        dp[key] = 0
    else:
        dp[key] = 1 + getLeftCount(h, w-1)
    return dp[key]
def getDownCount(h, w):
    key = str(h) + str(w) + 'd'
    if key in dp:
        return dp[key]
    elif s[h][w] == '#':
        dp[key] = 0
    elif h == H - 1:
        dp[key] = 0
    elif s[h+1][w] == '#':
        dp[key] = 0
    else:
        dp[key] = 1 + getDownCount(h+1, w)
    return dp[key]
def getUpCount(h, w):
    key = str(h) + str(w) + 'u'
    if key in dp:
        return dp[key]
    elif s[h][w] == '#':
        dp[key] = 0
    elif h == 0:
        dp[key] = 0
    elif s[h-1][w] == '#':
        dp[key] = 0
    else:
        dp[key] = 1 + getUpCount(h-1, w)
    return dp[key]
def getCount(h, w):
    if s[h][w] == '#':
        return 0
    rCnt, lCnt, uCnt, dCnt = 0,0,0,0
    key = str(h) + str(w)
    # to right
    rkey = key + 'r'
    rCnt = getRightCount(h, w)
    # to left
    lkey = key + 'l'
    lCnt = getLeftCount(h, w)
    # to down
    dkey = key + 'd'
    dCnt = getDownCount(h, w)
    # to up
    ukey = key + 'u'
    uCnt = getUpCount(h, w)
    return rCnt + lCnt + uCnt + dCnt + 1

for i in reversed(range(H)):
    for j in reversed(range(W)):
        ans = max(ans, getCount(i, j))
print(ans)

Submission status: Runtime Error

Solution code:
# coding: utf-8
# Your code here!
def up(w,h,count):
    if h==-1:
        return count-1
    elif S[h][w]=="#":
        return count-1
    else:
        count=up(w,h-1,count+1)
    return count

def down(w,h,count):
    if h==H:
        return count-1
    elif S[h][w]=="#":
        return count-1
    else:
        count=down(w,h+1,count+1)
    return count
        
def right(w,h,count):
    if w==W:
        return count-1
    elif S[h][w]=="#":
        return count-1
    else:
        count=right(w+1,h,count+1)
    return count

def left(w,h,count):
    if w==-1:
        return count-1
    elif S[h][w]=="#":
        return count-1
    else:
        count=left(w-1,h,count+1)
    return count

H,W=map(int,input().split())
S=[]

for _ in range(H):
    S.append(list(input()))

ans=0
for h in range(H):
    for w in range(W):
        if S[h][w]=="#":
            continue
        ans=max((up(w,h,0)+down(w,h,0)+right(w,h,0)+left(w,h,0)),ans)
        
        """
        if ans==(up(w,h,0)+down(w,h,0)+right(w,h,0)+left(w,h,0)):
            print(h,w)
            print(up(w,h,0),down(w,h,0),right(w,h,0),left(w,h,0))
        """
print(ans+1)

Submission status: Runtime Error

Solution code:
H, W = map(int, input().split())
s = []
ans = 0
dp = {}
for i in range(H):
    s.append(input())

def getCount(h, w):
    if s[h][w] == '#':
	return 0
    rCnt = 0
    lCnt = 0
    uCnt = 0
    dCnt = 0
    key = str(h) + str(w)

    # to right
    rkey = key + 'r'
    if rkey in dp:
	rCnt = dp[rkey]
    else:
        for i in range(w+1, W):
            if s[h][i] == '.':
		rCnt += 1
            else:
                break
	dp[rkey] = rCnt

    # to left
    lkey = key + 'l'
    if lkey in dp:
	lCnt = dp[lkey]
    else:
        for i in reversed(range(w)):
            if s[h][i] == '.':
		lCnt += 1
            else:
                break
	dp[lkey] = lCnt

    # to down
    dkey = key + 'd'
    if dkey in dp:
	dCnt = dp[dkey]
    else:
        for i in range(h+1, H):
            if s[i][w] == '.':
		dCnt += 1
            else:
                break
	dp[dkey] = dCnt

    # to up
    ukey = key + 'u'
    if ukey in dp:
	uCnt = dp[ukey]
    else:
        for i in reversed(range(h)):
            if s[i][w] == '.':
		uCnt += 1
            else:
                break
	dp[ukey] = uCnt

    return rCnt + lCnt + uCnt + dCnt + 1

for i in reversed(range(H)):
    for j in reversed(range(W)):
	ans = max(ans, getCount(i, j))

print(ans)

Submission status: Runtime Error

Solution code:
def dpWcount(a,b,dpW,k):
    if S[a][b]==".":
        if b<W-1:
            k +=1
            dpW[a][b] = dpWcount(a,b+1,dpW,k)
        else:
            dpW[a][b] = k+1
        return dpW[a][b]
    else:
       dpW[a][b] = 0
       return k
def dpHcount(a,b,dpH,k):
    if S[a][b]==".":
        if a<H-1:
            k +=1
            dpH[a][b] = dpHcount(a+1,b,dpH,k)
        else:
            dpH[a][b] = k+1
        return dpH[a][b]
    else:
       dpH[a][b] = 0
       return k

import sys
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LIS(): return list(map(str,sys.stdin.readline().split()))
ans = int(1)
ansC = int(0)

H, W = LI()
S = [str(input()) for _ in range(H)]
dpW = [[0]*W for _ in range(H)]
dpH = [[0]*W for _ in range(H)]

for i in range(H):
    w = int(0)
    while w<W:
        k = int(0)
        w += max(dpWcount(i,w, dpW, k),1)

#print(dpW)

for i in range(W):
    h = int(0)
    while h<H:
        k = int(0)
        h += max(dpHcount(h,i, dpH, k),1)

#print(dpH)

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

Submission status: Runtime Error

Solution code:
def dpWcount(a,b,dpW,k):
    count = int(0)
    if S[a][b]==".":
        if b<W-1:
            k +=1
            dpW[a][b] = dpWcount(a,b+1,dpW,k)
        else:
            dpW[a][b] = k+1
            k = int(0)
        return dpW[a][b]
    else:
       dpW[a][b] = 0
       count = k
       k = int(0)
       return count
def dpHcount(a,b,dpH,k):
    count = int(0)
    if S[a][b]==".":
        if a<H-1:
            k +=1
            dpH[a][b] = dpHcount(a+1,b,dpH,k)
        else:
            dpH[a][b] = k+1
            k = int(0)
        return dpH[a][b]
    else:
       dpH[a][b] = 0
       count = k
       k = int(0)
       return count

import sys
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LIS(): return list(map(str,sys.stdin.readline().split()))
ans = int(1)
ansC = int(0)

H, W = LI()
S = [str(input()) for _ in range(H)]
dpW = [[0]*W for _ in range(H)]
dpH = [[0]*W for _ in range(H)]

for i in range(H):
    w = int(0)
    while w<W:
        k = int(0)
        w += max(dpWcount(i,w, dpW, k),1)

Submission status: Runtime Error

Solution code:
def dpWcount(a,b,dpW,k):
    count = int(0)
    if S[a][b]==".":
        if b<W-1:
            k +=1
            dpW[a][b] = dpWcount(a,b+1,dpW,k)
        else:
            dpW[a][b] = k+1
            k = int(0)
        return dpW[a][b]
    else:
       dpW[a][b] = 0
       count = k
       k = int(0)
       return count
def dpHcount(a,b,dpH,k):
    count = int(0)
    if S[a][b]==".":
        if a<H-1:
            k +=1
            dpH[a][b] = dpHcount(a+1,b,dpH,k)
        else:
            dpH[a][b] = k+1
            k = int(0)
        return dpH[a][b]
    else:
       dpH[a][b] = 0
       count = k
       k = int(0)
       return count


import sys
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LIS(): return list(map(str,sys.stdin.readline().split()))
ans = int(1)
ansC = int(0)

H, W = LI()
S = [str(input()) for _ in range(H)]
dpW = [[0]*W for _ in range(H)]
dpH = [[0]*W for _ in range(H)]

for i in range(H):
    w = int(0)
    while w<W:
        k = int(0)
        w += max(dpWcount(i,w, dpW, k),1)

#print(dpW)

for i in range(W):
    h = int(0)
    while h<H:
        k = int(0)
        h += max(dpHcount(h,i, dpH, k),1)

#print(dpH)

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

Submission status: Runtime Error

Solution code:
def dpWcount(a,b,dpW,k):
    count = int(0)
    if S[a][b]==".":
        if b<W-1:
            k +=1
            dpW[a][b] = dpWcount(a,b+1,dpW,k)
        else:
            dpW[a][b] = k+1
            k = int(0)
        return dpW[a][b]
    else:
       dpW[a][b] = 0
       count = k
       k = int(0)
       return count
def dpHcount(a,b,dpH,k):
    count = int(0)
    if S[a][b]==".":
        if a<H-1:
            k +=1
            dpH[a][b] = dpHcount(a+1,b,dpH,k)
        else:
            dpH[a][b] = k+1
            k = int(0)
        return dpH[a][b]
    else:
       dpH[a][b] = 0
       count = k
       k = int(0)
       return count


import sys
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LIS(): return list(map(str,sys.stdin.readline().split()))
ans = int(1)

H, W = LI()
S = [str(input()) for _ in range(H)]
dpW = [[0]*W for _ in range(H)]
dpH = [[0]*W for _ in range(H)]

for i in range(H):
    w = int(0)
    while w<W:
        k = int(0)
        w += max(dpWcount(i,w, dpW, k),1)

#print(dpW)

for i in range(W):
    h = int(0)
    while h<H:
        k = int(0)
        h += max(dpHcount(h,i, dpH, k),1)

#print(dpH)

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

Submission status: Runtime Error

Solution code:
def dpWcount(a,b,dpW,k):
    count = int(0)
    if S[a][b]==".":
        if b<W-1:
            k +=1
            dpW[a][b] = dpWcount(a,b+1,dpW,k)
        else:
            dpW[a][b] = k+1
            k = int(0)
        return dpW[a][b]
    else:
       dpW[a][b] = 0
       count = k
       k = int(0)
       return count
def dpHcount(a,b,dpH,k):
    count = int(0)
    if S[a][b]==".":
        if a<H-1:
            k +=1
            dpH[a][b] = dpHcount(a+1,b,dpH,k)
        else:
            dpH[a][b] = k+1
            k = int(0)
        return dpH[a][b]
    else:
       dpH[a][b] = 0
       count = k
       k = int(0)
       return count


import sys
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LIS(): return list(map(str,sys.stdin.readline().split()))
mod = 10**9 + 7
inf = float('inf')
ans = int(1)

H, W = LI()
S = [str(input()) for _ in range(H)]
dpW = [[0]*W for _ in range(H)]
dpH = [[0]*W for _ in range(H)]

for i in range(H):
    w = int(0)
    while w<W:
        k = int(0)
        w += max(dpWcount(i,w, dpW, k),1)

#print(dpW)

for i in range(W):
    h = int(0)
    while h<H:
        k = int(0)
        h += max(dpHcount(h,i, dpH, k),1)

#print(dpH)

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

Submission status: Runtime Error

Solution code:
def dpWcount(a,b,dpW,k):
    count = int(0)
    if S[a][b]==".":
        if b<W-1:
            k +=1
            dpW[a][b] = dpWcount(a,b+1,dpW,k)
        else:
            dpW[a][b] = k+1
            k = int(0)
        return dpW[a][b]
    else:
       dpW[a][b] = 0
       count = k
       k = int(0)
       return count
def dpHcount(a,b,dpH,k):
    count = int(0)
    if S[a][b]==".":
        if a<H-1:
            k +=1
            dpH[a][b] = dpHcount(a+1,b,dpH,k)
        else:
            dpH[a][b] = k+1
            k = int(0)
        return dpH[a][b]
    else:
       dpH[a][b] = 0
       count = k
       k = int(0)
       return count


import heapq
import sys
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LIS(): return list(map(str,sys.stdin.readline().split()))
mod = 10**9 + 7
inf = float('inf')
ans = []

H, W = LI()
S = [str(input()) for _ in range(H)]
dpW = [[0]*W for _ in range(H)]
dpH = [[0]*W for _ in range(H)]

for i in range(H):
    w = int(0)
    while w<W:
        k = int(0)
        w += max(dpWcount(i,w, dpW, k),1)

#print(dpW)

for i in range(W):
    h = int(0)
    while h<H:
        k = int(0)
        h += max(dpHcount(h,i, dpH, k),1)

#print(dpH)

for i in range(H):
    for j in range(W):
        ansC = dpW[i][j] + dpH[i][j]
        ans.append(ansC)
print(max(ans)-1)