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 math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9 + 7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def pe(s): return print(str(s), file=sys.stderr)
def JA(a, sep): return sep.join(map(str, a))


def main():
    n,m = LI()
    a = [[c!='.' for c in l] for l in sys.stdin.readlines()] + [[True] * m]
    b = [[None] * n for _ in range(m)]
    for i in range(n):
        j = 0
        ai = a[i] + [True]
        while j < m:
            if ai[j]:
                j += 1
            else:
                k = j+1
                while not ai[k]:
                    k += 1
                s = k - j
                b[j][i] = s
                if k < m:
                    b[k][j] = 0
                j = k

    r = 0
    c = [0] * n
    for j in range(m):
        bj = b[j]
        for i in range(n):
            if bj[i] is None:
                continue
            c[i] = bj[i]
        i = 0
        while i < n:
            if a[i][j]:
                i += 1
            else:
                k = i+1
                while not a[k][j]:
                    k += 1
                t = max(c[i:k]) + k - i
                if r < t:
                    r = t
                i = k

    return r - 1


print(main())

Submission status: Runtime Error

Solution code:
import numpy as np
 
H, W = map(int, input().split())
S = [input() for _ in range(H)]
 
light = np.array([[-1, -1] for _ in range(H*W)])
 
for i in range(H):
    for j in range(W):
        if S[i][j] == '#':
            continue
        
        if light[W*i+j][0] == -1:
            tmp = 0
            tate = i
            while tate < H and S[tate][j] == '.':
                tmp += 1
                tate += 1
            for k in range(tmp):
                light[W*(i+k)+j][0] = tmp
        
        if light[W*i+j][1] == -1:
            tmp = 0
            yoko = j
            while yoko < W and S[i][yoko] == '.':
                tmp += 1
                yoko += 1
            for k in range(tmp):
                light[W*i+j+k][1] = tmp
 
 
print(np.max(light.sum(axis=1))-1)

Submission status: Runtime Error

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

if h == 1 and w == 1:
    print(s[100000][100000])
    if s[0][0] == '.':
        print(1)
    else:
        print(0)
    exit()
elif h == 1:
    a = [0] * w
    mode = 0
    for i in range(w):
        if mode == 0:
            if s[0][i] == '.':
                c = 1
                a[i] = c
                mode = 1
        else:
            if s[0][i] == '.':
                c += 1
                a[i] = c
            else:
                mode = 0
    print(max(a))
    exit()
elif w == 1:
    b = [0] * h
    mode = 0
    for i in range(h):
        if mode == 0:
            if s[i][0] == '.':
                c = 1
                b[i] = c
                mode = 1
        else:
            if s[i][0] == '.':
                c += 1
                b[i] = c
            else:
                mode = 0
    print(max(b))
    exit()

exit()

a = [[0 for _ in range(w)] for _ in range(h)]
b = [[0 for _ in range(w)] for _ in range(h)]

c = 0

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

    for j in range(w-2, -1, -1):
        if a[i][j+1] > 0 and a[i][j] > 0:
            a[i][j] = a[i][j+1]

ans = 0

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

    #print(b)

    for i in range(h-2, -1, -1):
        if b[i+1][j] > 0 and b[i][j] > 0:
            b[i][j] = b[i+1][j]
            ans = max(ans, a[i][j] + b[i][j] - 1)
        elif b[i][j] > 0:
            ans = max(ans, a[i][j] + b[i][j] - 1)

print(ans)

Submission status: Runtime Error

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

if h == 1 and w == 1:
    if s[0][0] == '.':
        print(1)
    else:
        print(0)
    exit()
elif h == 1:
    print(s[100000][1000000])
    a = [0] * w
    mode = 0
    for i in range(w):
        if mode == 0:
            if s[0][i] == '.':
                c = 1
                a[i] = c
                mode = 1
        else:
            if s[0][i] == '.':
                c += 1
                a[i] = c
            else:
                mode = 0
    print(max(a))
    exit()
elif w == 1:
    b = [0] * h
    mode = 0
    for i in range(h):
        if mode == 0:
            if s[i][0] == '.':
                c = 1
                b[i] = c
                mode = 1
        else:
            if s[i][0] == '.':
                c += 1
                b[i] = c
            else:
                mode = 0
    print(max(b))
    exit()

exit()

a = [[0 for _ in range(w)] for _ in range(h)]
b = [[0 for _ in range(w)] for _ in range(h)]

c = 0

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

    for j in range(w-2, -1, -1):
        if a[i][j+1] > 0 and a[i][j] > 0:
            a[i][j] = a[i][j+1]

ans = 0

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

    #print(b)

    for i in range(h-2, -1, -1):
        if b[i+1][j] > 0 and b[i][j] > 0:
            b[i][j] = b[i+1][j]
            ans = max(ans, a[i][j] + b[i][j] - 1)
        elif b[i][j] > 0:
            ans = max(ans, a[i][j] + b[i][j] - 1)

print(ans)

Submission status: Runtime Error

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

if h == 1 and w == 1:
    if s[0][0] == '.':
        print(1)
    else:
        print(0)
    exit()
elif h == 1:
    a = [0] * w
    mode = 0
    for i in range(w):
        if mode == 0:
            if s[0][i] == '.':
                c = 1
                a[i] = c
                mode = 1
        else:
            if s[0][i] == '.':
                c += 1
                a[i] = c
            else:
                mode = 0
    print(max(a))
    exit()
elif w == 1:
    print(s[100000][1000000])
    b = [0] * h
    mode = 0
    for i in range(h):
        if mode == 0:
            if s[i][0] == '.':
                c = 1
                b[i] = c
                mode = 1
        else:
            if s[i][0] == '.':
                c += 1
                b[i] = c
            else:
                mode = 0
    print(max(b))
    exit()

exit()

a = [[0 for _ in range(w)] for _ in range(h)]
b = [[0 for _ in range(w)] for _ in range(h)]

c = 0

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

    for j in range(w-2, -1, -1):
        if a[i][j+1] > 0 and a[i][j] > 0:
            a[i][j] = a[i][j+1]

ans = 0

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

    #print(b)

    for i in range(h-2, -1, -1):
        if b[i+1][j] > 0 and b[i][j] > 0:
            b[i][j] = b[i+1][j]
            ans = max(ans, a[i][j] + b[i][j] - 1)
        elif b[i][j] > 0:
            ans = max(ans, a[i][j] + b[i][j] - 1)

print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np

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

left=[[0]*w for i in range(h)]
right=[[0]*w for i in range(h)]
up=[[0]*w for i in range(h)]
down=[[0]*w for i in range(h)]
count=[[0]*w for i in range(h)]

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

for i in range(w):
  if s[i][0]==".":
    up[i][0]=1
  for j in range(1,h-1):
    if s[i][j]==".":
      up[i][j]==up[i][j-1]+1
      
for i in range(w):
  if s[i][h-1]==".":
    down[i][h-1]=1
  for j in range(h-1):
    if s[i][j]==".":
      down[i][j]==down[i][j+1]+1
      
for i in range(w):
  for j in range(h):
    count[i][j]=left[i][j]+right[i][j]+up[i][j]+down[i][j]-3

saidai=np.array(count)
print(saidai.max())

Submission status: Runtime Error

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

def torf(k, x, y):
    if k==0:
        if s[x][y]=="#":
            return 0
        elif x == 0:
            return 1
        else :
            return 1+torf(k, x-1, y)
    elif k==1:
        if s[x][y]=="#":
            return 0
        elif y == w-1 :
            return 1
        else :
            return 1+torf(k, x, y+1)
    elif k==2:
        if s[x][y] == "#" :
            return 0
        elif x == h-1 :
            return 1
        else :
            return 1+torf(k, x+1, y)
    else :
        if s[x][y] == "#":
            return 0
        elif y == 0 :
            return 1
        else :
            return 1+torf(k, x, y-1)

def search(x, y):
    d=0
    for k in range(4):
        d+=torf(k, x, y)
    return d-3
max = 1
for i in range(h):
    for j in range(w):
        if s[i][j] == ".":
            if max < search(i, j):
                max = search(i, j)
print (max)

Submission status: Runtime Error

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

def torf(i, x, y):
    if i==0:
        if s[x][y]=="#":
            return 0
        elif x == 0:
            return 1
        else :
            return 1+torf(i, x-1, y)
    elif i==1:
        if s[x][y]=="#":
            return 0
        elif y == w-1 :
            return 1
        else :
            return 1+torf(i, x, y+1)
    elif i==2:
        if s[x][y] == "#" :
            return 0
        elif x == h-1 :
            return 1
        else :
            return 1+torf(i, x+1, y)
    else :
        if s[x][y] == "#":
            return 0
        elif y == 0 :
            return 1
        else :
            return 1+torf(i, x, y-1)

def search(x, y):
    d=0
    for i in range(4):
        d+=torf(i, x, y)
    return d-3
max = 0
for i in range(h):
    for j in range(w):
        if s[i][j] == ".":
            if max < search(i, j):
                max = search(i, j)
print (max)

Submission status: Runtime Error

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

L = [[0]*w for _ in range(h)]
R = [[0]*w for _ in range(h)]
U = [[0]*w for _ in range(h)]
D = [[0]*w for _ in range(h)]
for i in range(h):
    pre = -1
    for j in range(w):
        if orimap[i][j]==".":
            L[i][j]=j-pre
        else:
            pre = j

for i in range(h):
    pre = w
    for j in range(w-1,-1,-1):
        if orimap[i][j]==".":
            R[i][j]=pre - j
        else:
            pre = j

for j in range(w):
    pre = -1
    for i in range(h):
        if orimap[i][j]==".":
            U[i][j]=i-pre
        else:
            pre = i

for j in range(h):
    pre = h
    for i in range(h-1,-1,-1):
        if orimap[i][j]==".":
            D[i][j]=pre-i
        else:
            pre = i

best = 0
for i in range(h):
    for j in range(w):
        res = L[i][j]+R[i][j]+U[i][j]+D[i][j]-3
        if res > best:
            best = res
print(best)

Submission status: Runtime Error

Solution code:
import numpy as np
h,w=map(int,input().split())
m=np.zeros((h,w))
c=np.zeros((h,w))
for i in range(h):
    s=input()
    for j in range(w):
        if s[j]=="#":
            m[i][j]=1

for i in range(h):
    j=0
    start=-1
    while(j<w):
        if start==-1:
            if m[i][j]==0:
                start=j
                count=1
        else:
            if m[i][j]==1:
                for k in range(start,j):
                    c[i][k]+=count
                start=-1
            else:
                count+=1
        j+=1
    if start!=-1:
        for k in range(start,w):
            c[i][k]+=count
for j in range(w):
    i=0
    start=-1
    while(i<h):
        if start==-1:
            if m[i][j]==0:
                start=i
                count=1
        else:
            if m[i][j]==1:
                for k in range(start,i):
                    c[k][j]+=count
                start=-1
            else:
                count+=1
        i+=1
    if start!=-1:
        for k in range(start,h):
            c[k][j]+=count
result=0
for i in range(h):
    for j in range(w):
        result=max(result,c[i][j])
print(result-1)

Submission status: Runtime Error

Solution code:
import numpy as np
h,w=map(int,input().split())
m=np.zeros(h,w)
c=np.zeros(h,w)
for i in range(h):
    s=input()
    for j in range(w):
        if s[j]=="#":
            m[i][j]=1

for i in range(h):
    j=0
    start=-1
    while(j<w):
        if start==-1:
            if m[i][j]==0:
                start=j
                count=1
        else:
            if m[i][j]==1:
                for k in range(start,j):
                    c[i][k]+=count
                start=-1
            else:
                count+=1
        j+=1
    if start!=-1:
        for k in range(start,w):
            c[i][k]+=count
for j in range(w):
    i=0
    start=-1
    while(i<h):
        if start==-1:
            if m[i][j]==0:
                start=i
                count=1
        else:
            if m[i][j]==1:
                for k in range(start,i):
                    c[k][j]+=count
                start=-1
            else:
                count+=1
        i+=1
    if start!=-1:
        for k in range(start,h):
            c[k][j]+=count
result=0
for i in range(h):
    for j in range(w):
        result=max(result,c[i][j])
print(result-1)

Submission status: Runtime Error

Solution code:
import numpy as np
import functools


def g(acc, x):
    if x == "#":
        res = 0
    elif acc:
        res = acc[-1] + 1
    else:
        res = 1
    acc.append(res)
    return acc


def h(acc, x):
    if x == 0:
        res = 0
    elif acc:
        res = max(acc[-1], x)
    else:
        res = x
    acc.append(res)
    return acc


def f(line):
    res = functools.reduce(g, line, [])
    res = functools.reduce(h, reversed(res), [])
    return res


H, W = map(int, input().split())
grid = np.array([list(input().strip()) for _ in range(H)])

row_wise = np.apply_along_axis(f, 0, grid)
col_wise = np.apply_along_axis(f, 1, grid)
print((row_wise + col_wise).max() - 1)

Submission status: Runtime Error

Solution code:
import numpy as np

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

for i in range(h):
    grid = []
    for i in range(h):
        grid.append(list(input()))
    grid = (np.array(grid) == ".") * 1  # ランプをおける:1, 障害物:0

grid = np.array(grid)

L = np.zeros((h, w), dtype=int)
R = np.zeros((h, w), dtype=int)
U = np.zeros((h, w), dtype=int)
D = np.zeros((h, w), dtype=int)

for j in range(w):
    if j == 0:
        L[:, j] = grid[:, j]
    else:
        L[:, j] = (L[:, j - 1] + 1) * grid[:, j]


for j in range(w - 1, -1, -1):
    if j >= w - 1:
        R[:, j] = grid[:, j]
    else:
        R[:, j] = (R[:, j + 1] + 1) * grid[:, j]

for i in range(h):
    if i <= 0:
        U[i, :] = grid[i, :]
    else:
        U[i, :] = (U[i - 1, :] + 1) * grid[i, :]


for i in range(h - 1, -1, -1):
    if i >= h - 1:
        D[i, :] = grid[i, :]
    else:
        D[i, :] = (D[i + 1, :] + 1) * grid[i, :]

print(np.max(L + R + U + D - 3))

Submission status: Runtime Error

Solution code:

"""
左・上からゴリゴリ攻めていくパターン
一回通ったかどうかのフラグが必要
"""

cnt = [[0] * (W+1) for i in range(H+1)]
# 横
for i in range(H):
    done = [False] * (W+1)
    for j in range(W):
        l = 0
        if done[j]: continue
        if S[i][j] == ".":
            while j+l < W:
                if S[i][j+l] == ".":
                    l += 1
                else:
                    break
        for k in range(j,j+l):
            cnt[i][k] += l
            done[k] = True

# 縦
for j in range(W):
    done = [False] * (H+1)
    for i in range(H):
        l = 0
        if done[i]: continue
        if S[i][j] == ".":
            while i+l < H:
                if S[i+l][j] == ".":
                    l += 1
                else:
                    break
        for k in range(i,i+l):
            cnt[k][j] += l
            done[k] = True

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

Submission status: Runtime Error

Solution code:
import sys

import numpy as np

h, w = list(map(int, input().split()))
field = [[int(c == '.') for c in line.rstrip()] for line in sys.stdin]
field = np.array(field)


def cumsum(f):
    result = np.zeros((h, w), dtype=np.int)
    for i, row in enumerate(f):
        ri = result[i]
        tmp = 0
        for j, c in enumerate(row):
            tmp = (tmp + c) * c
            ri[j] += tmp
        tmp = 0
        for j, c in reversed(list(enumerate(row))):
            tmp = (tmp + c) * c
            ri[j] += tmp
    return result


ans = cumsum(field)
ans += cumsum(field.T).T

print(ans.max() - 3)

Submission status: Runtime Error

Solution code:
import numpy as np
H,W=map(int,input().split())
S=[list(input()) for h in range(H)]
S=[[1 if s=='.' else 0 for s in S[h]] for h in range(H)]
S=np.array(S)
L=S.copy()
R=S.copy()
U=S.copy()
D=S.copy()
for w in range(1,W):
    L[:,w]=(L[:,w-1]+1)*S[:,j]
    R[:,-(1+w)]=(R[:,-w]+1)*S[:,-(1+w)]
for h in range(1,H):
    U[h,:]=(U[h-1,:]+1)*S[h,:]
    D[-(1+h),:]=(D[-h,:]+1)*S[-(1+h),:]
print(int((L+R+U+D).max())-3)

Submission status: Runtime Error

Solution code:
h, w = map(int, input().split())
s = []
l = []
r = []
u = []
d = []
for i in range(h):
  s.append(input())
  l.append([0 for j in range(w)])
  r.append([0 for j in range(w)])
  u.append([0 for j in range(w)])
  d.append([0 for j in range(w)])
  
# lみる
for x in range(w):
  for y in range(h):
    if s[y][x] == '.':
      if x == 0:
        l[y][x] = 1
      else:
        l[y][x] = l[y][x-1] + 1
 
# rみる
for x in range(w):
  for y in range(h):
    if s[h-1-y][w-1-x] == '.':
      if x == 0:
        r[y][x] = 1
      else:
        r[y][x] = r[y][x+1] + 1
 
# uみる
for y in range(h):
  for x in range(w):
    if s[y][x] == '.':
      if y == 0:
        u[y][x] = 1
      else:
        u[y][x] = u[y-1][x] + 1
 
# dみる
for y in range(h):
  for x in range(w):
    if s[h-1-y][w-1-x] == '.':
      if y == 0:
        d[y][x] = 1
      else:
        d[y][x] = d[y+1][x] + 1
 
 
max_all = 0
for y in range(h):
  for x in range(w):
    max_tmp = l[y][x] + r[y][x] + u[y][x] + d[y][x]
    if max_tmp > max_all:
      max_all = max_tmp
      
print(max_all - 3)

Submission status: Runtime Error

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

cnt = [[None] * w for i in range(h)]
for i in range(h):
    j = 0
    while j < w:
        if s[i][j] == '#':
            cnt[i][j] = 0
            j += 1
            continue
        l = 0
        while j+l < w:
            if s[i][j+l] == '#':
                break
            l += 1
        for k in range(l):
            cnt[i][j+k] = l
        j += l

for i in range(w):
    j = 0
    while j < h:
        if s[j][i] == '#':
            cnt[i][j] = 0
            j += 1
            continue
        l = 0
        while j+l < h:
            if s[j+l][i] == '#':
                break
            l += 1
        for k in range(l):
            cnt[j+k][i] += l
        j += l

ans = 0
for i in range(h):
    for j in range(w):
        ans = max(ans, cnt[i][j])

Submission status: Runtime Error

Solution code:
h, w = map(int, input().split())
s = []
l = []
r = []
u = []
d = []
for i in range(h):
  s.append(input())
  l.append([0 for j in range(w)])
  r.append([0 for j in range(w)])
  u.append([0 for j in range(w)])
  d.append([0 for j in range(w)])
  
# lみる
for x in range(w):
  for y in range(h):
    if s[y][x] == '.':
      if x == 0:
        l[y][x] = 1
      else:
        l[y][x] = l[y][x-1] + 1
 
# rみる
for x in range(w):
  for y in range(h):
    if s[h-1-y][w-1-x] == '.':
      if x == w-1:
        l[y][x] = 1
      else:
        l[y][x] = l[y][x+1] + 1
 
# uみる
for x in range(w):
  for y in range(h):
    if s[y][x] == '.':
      if y == 0:
        l[y][x] = 1
      else:
        l[y][x] = l[y-1][x] + 1

# dみる
for x in range(w):
  for y in range(h):
    if s[h-1-y][w-1-x] == '.':
      if y == h-1:
        l[y][x] = 1
      else:
        l[y][x] = l[y+1][x] + 1
 

max_all = 0
for y in range(h):
  for x in range(w):
  max_tmp = l[y][x] + r[y][x] + u[y][x] + d[y][x]
  if max_tmp > max_all:
    max_all = max_tmp
print(max_all - 3)

Submission status: Runtime Error

Solution code:
s = []
s_conn = []
for i in range(h):
  s.append(input())
  s_conn.append([[0]*2 for j in range(w)])
 
# 縦にみる
for x in range(w):
  start = 0
  count = 0
  for y in range(h):
    if s[y][x] == '.':
      count += 1
      if y == h-1:
        for i in range(start, y):
          s_conn[i][x][0] = count
    else:
      for i in range(start, y):
        s_conn[i][x][0] = count
      count = 0
      start = y+1
 
# 横にみる
for y in range(h):
  start = 0
  count = 0
  for x in range(w):
    if s[y][x] == '.':
      count += 1
      if x == w-1:
        for i in range(start, x):
          s_conn[y][i][1] = count
    else:
      for i in range(start, x):
        s_conn[y][i][1] = count
      count = 0
      start = x+1

max_all = 0
for i in range(h):
  max_tmp = max(map(sum, s_conn[i]))
  if max_tmp > max_all:
    max_all = max_tmp
print(max_all - 1)

Submission status: Runtime Error

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

y_cnt = [[0 for j in range(w)] for _ in range(h)]
x_cnt = [[0 for j in range(w)] for _ in range(h)]

yy, xx = 0, 0

def dfs1(y, x, cnt):
    global yy, h, s, y_cnt
    yy = max(yy, y)
    if y >= h or s[y][x] == '#':
        return cnt
    y_cnt[y][x] = dfs1(y + 1, x, cnt + 1)
    return y_cnt[y][x]
    
def dfs2(y, x, cnt):
    global xx, w, s, x_cnt
    xx = max(xx, x)
    if x >= w or s[y][x] == '#':
        return cnt
    x_cnt[y][x] = dfs2(y, x + 1, cnt + 1)
    return x_cnt[y][x]
    
for j in range(w):
    yy, i = 0, 0
    while(i < h):
        dfs1(i, j, 0)
        i = yy + 1

for i in range(h):
    xx, j = 0, 0
    while(j < w):
        dfs2(i, j, 0)
        j = xx + 1

ans = 0
for i in range(h):
    for j in range(w):
        ans = max(ans, y_cnt[i][j] + x_cnt[i][j] - 1)
        
print(ans)

Submission status: Runtime Error

Solution code:
h, w = map(int, input().split())
s = []
s_conn = []
for i in range(h):
  s.append(input())
  s_conn.append([[0]*2 for j in range(w)])

# 縦にみる
for x in range(w):
  start = 0
  count = 0
  for y in range(h):
    if s[y][x] = '.':
      count += 1
      if y == h-1:
        for i in range(start, y):
          s_conn[i][x][0] = count
    else:
      for i in range(start, y):
        s_conn[i][x][0] = count
      count = 0
      start = y+1

# 横にみる
for y in range(h):
  start = 0
  count = 0
  for x in range(w):
    if s[y][x] = '.':
      count += 1
      if x == w-1:
        for i in range(start, x):
          s_conn[y][i][0] = count
    else:
      for i in range(start, x):
        s_conn[y][i][0] = count
      count = 0
      start = x+1

max_all = 0
for i in range(h):
  max_tmp = max(map(sum, s_conn[i]))
  if max_tmp > max_all:
    max_all = max_tmp
print(max_all - 1)

Submission status: Runtime Error

Solution code:
h, w = map(int, input().split())
s = []
s_conn = []
for i in range(h):
  s.append(input())
  s_conn.append([[0]*2 for j in range(w)])

# 縦にみる
for x in range(w):
  start = 0
  count = 0
  for y in range(h):
    if s[y][x] = '.':
      count += 1
      if y == h-1:
        for i in range(start, y):
          s_conn[i][x][0] = count
    else:
      for i in range(start, y):
        s_conn[i][x][0] = count
      count = 0
      start = y+1

# 横にみる
for y in range(h):
  start = 0
  count = 0
  for x in range(w):
    if s[y][x] = '.':
      count += 1
      if x == w-1:
        for i in range(start, x):
          s_conn[y][i][0] = count
    else:
      for i in range(start, x):
        s_conn[y][i][0] = count
      count = 0
      start = x+1

print(max(map(sum, s_conn)) - 1)

Submission status: Runtime Error

Solution code:
def solve():
    h, w = map(int, input().split())
    S = list(input() + '#' for _ in range(h)) + ['#' * (w + 1)]
    H = [[0] * w for _ in range(h + 1)]
    W = [[0] * w for _ in range(h + 1)]
    def f(r, c, num):
        if W[r][c] == 0:
            if c < w and S[r][c + 1] == '.':
                W[r][c] = f(r, c + 1, num + 1)
            else:
                W[r][c] = num
        return W[r][c]
    def g(r, c, num):
        if H[r][c] == 0:
            if r < h and S[r + 1][c] == '.':
                H[r][c] = g(r + 1, c, num + 1)
            else:
                H[r][c] = num
        return H[r][c]
    ans = 0
    for r in range(h):
        for c in range(w):
            if S[r][c] == '.':
                ans = max(ans, f(r, c, 1) + g(r, c, 1) - 1)
    print(ans)
solve()

Submission status: Runtime Error

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

cnt = [[0 for _ in range(W)] for _ in range(H)]
for i in range(H):
  done = [0 for _ in range(W)]
  for j in range(W):
    if S[i][j] == "#":
      continue
    if done[j]:
      continue
    l = 0
    while j + l < W:
      if S[i][j] == "#":
        break
      l += 1
    for k in range(l):
      cnt[i][j + k] += l
      done[j + k] = 1

for i in range(W):
  done = [0 for _ in range(H)]
  for j in range(H):
    if S[i][j] == "#":
      continue
    if done[i]:
      continue
    l = 0
    while i + l < H:
      if S[i][j] == "#":
        break
      l += 1
    for k in range(l):
      cnt[i + k][j] += l
      done[i + k] = 1

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

Submission status: Runtime Error

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

L = [[0 for i in range(W)] for j in range(W)]
R = [[0 for i in range(W)] for j in range(W)]
U = [[0 for i in range(W)] for j in range(W)]
D = [[0 for i in range(W)] for j in range(W)]

ans=0

for i in range(H):
    for j in range(W):
        if S[i][j]=='.':
            if j==0:
                L[i][j]=1
            else:
                L[i][j]=L[i][j-1]+1
        if S[i][-j-1]=='.':
            if j==0:
                R[i][-j-1]=1
            else:
                R[i][-j-1]=R[i][-j]+1
        if S[i][j]=='.':
            if i==0:
                U[i][j]=1
            else:
                U[i][j]=U[i-1][j]+1
        if S[-i-1][j]=='.':
            if i==0:
                D[-i-1][j]=1
            else:
                D[-i-1][j]=D[-i][j]+1
for i in range(H):
    for j in range(W):
        ans = max(ans,L[i][j]+R[i][j]+U[i][j]+D[i][j]-3)
print(ans)