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 numpy as np
import sys
buf = sys.stdin.buffer

H,W = map(int,buf.readline().split())
# 周りに壁を、0,1化、壁を0で持つ
grid = np.zeros((H+2,W+2),dtype=np.bool)
grid[1:-1,1:] = (np.frombuffer(buf.read(H*(W+1))+b'\n',dtype='S1') == b'.').reshape((H,W+1))

# x軸方向の集計
def F(transpose):
  x = grid
  if transpose:
    x = (x.T).copy()
  x = np.ravel(x) # to 1D array
  L = len(x)
  
  left_zero = -np.arange(L) # 左の壁のindexの-1倍
  left_zero[x] = 0
  np.minimum.accumulate(left_zero, out=left_zero)
  
  right_zero = np.arange(L) # 逆順ソートした上で左の壁のindex
  right_zero[x[::-1]] = 0
  np.maximum.accumulate(right_zero, out=right_zero)
  
  y = left_zero
  y += L-right_zero[::-1]
  
  return y.reshape(grid.T.shape).T if transpose else y.reshape(grid.shape)
  
answer = (F(False) + F(True)).max()-5
print(answer)

Submission status: Runtime Error

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

H, W = map(int, input().split())
S = np.array([list(input()) for _ in range(H)]) == '.'
ups = np.zeros((H,W), dtype=int)
downs = np.zeros((H,W), dtype=int)
lefts = np.zeros((H,W), dtype=int)
rights = np.zeros((H,W), dtype=int)

for h in range(H):
    ups[h] = (ups[h-1] + 1) * S[h-1]
    downs[H-h-1] = (downs[H-h-1] + 1) * S[H-h-1]
for w in range(W):
    lefts[:, w] = (lefts[:, w-1] + 1) * S[w-1]
    rights[:, W-w-1] = (rights[:, W-w-1] + 1) * S[W-w-1]
print(np.amax((ups+downs+lefts+rights)*S)+1)

Submission status: Runtime Error

Solution code:
#   ABC129　D問題
import numpy as np

H, W = map(int, input().split())    #   1 <= H, W <= 2000
S_arr = []
for _ in range(H):
    S_arr.append(list(input()))

point_arr = np.zeros((H, W))

start = 0
stop = W
for y in range(H):
    start = 0
    stop = W
    for x in range(W):
        if S_arr[y][x] == "#":
            stop = x
            point_arr[y, start:stop] += stop - start
            start = stop + 1
    point_arr[y, start:W] += W - start
    

for x in range(W):  #   コードのコピペ禁止の原則に違反してるけど、改善方法が思いつかない問題
    start = 0
    stop = H
    for y in range(H):
        if S_arr[y][x] == "#":
            stop = y
            point_arr[start:stop, x] += stop - start
            start = stop + 1
    point_arr[start:H, x] += H - start

print(int(np.max(point_arr))-1) 
#   O(H*W)程度の計算量で十分高速だと思ってたのに、そうでもない問題
#   2019/06/10 現在未解決　PyPy使ったらどうなるのかやってみた。Numpy含まれてるからランタイムエラーになるのだろうか？

Submission status: Runtime Error

Solution code:
import numpy as np
import sys


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


def get_data(stream):
    buf = b''
    b = stream.buffer.read(1)
    while b != b'\n':
        buf += b
        b = stream.buffer.read(1)
    H, W = map(int, buf.split())
    c = stream.buffer.read(H * (W + 1))
    arr = np.array(c.split())
    arr = np.frombuffer(arr, dtype='S1').reshape((H, W))
    return H, W, arr


def main():
    start = time.time()
    H, W, arr = get_data(sys.stdin)
    a = np.zeros((H + 1, W + 1), dtype='i8')
    a[:-1, :-1] = arr == b'.'
    end = time.time()
    print(end - start)

    calc(a, H, W)
    print(a.max())


if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
h,w = map(int,input().split())
l=['#'*(w+2)]+['#'+input()+'#' for i in range(h)]+['#'*(w+2)]
dp = [[[0]*2 for i in range(w+2)] for i in range(h+2)]
cnt = 0
ans = 0

def dfsw(x,y,cnt):
  if l[x][y+1] == '.':
    cnt += 1
    dp[x][y][0] = dfsw(x,y+1,cnt)
    return dp[x][y][0]
  else:
    dp[x][y][0] = cnt
    return dp[x][y][0]

def dfsh(x,y,cnt):
  if l[x+1][y] == '.':
    cnt += 1
    dp[x][y][1] = dfsh(x+1,y,cnt)
    return dp[x][y][1]
  else:
    dp[x][y][1] = cnt
    return dp[x][y][1]

for i in range(h+2):
  for j in range(w+2):
    if l[i][j] == '.' and dp[i][j][0] == 0:
      dfsw(i,j,1)
for i in range(h+2):
  for j in range(w+2):
    if l[i][j] == '.' and dp[i][j][1] == 0:
      dfsh(i,j,1)
    
for i in range(h+2):
  for j in range(w+2):
    if l[i][j] == '.':
      ans = max(ans, sum(dp[i][j]) - 1)
print(ans)

Submission status: Runtime Error

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


def D_w(i, j, w):
    if not(0 <= j < W) or S[i][j] == '#':
        return w
    if S[i][j] == '.':
        w = D_w(i, j + 1, w + 1)
        memo_W[i][j] = w
        return w


def D_h(i, j, w):
    if not(0 <= i < H) or S[i][j] == '#':
        return w
    if S[i][j] == '.':
        w = D_h(i + 1, j, w + 1)
        memo_H[i][j] = w
        return w


ans = 0
for i in range(H):
    for j in range(W):
        if memo_W[i][j] == 0:
            memo_W[i][j] = D_w(i, j, 0)
        if memo_H[i][j] == 0:
            memo_H[i][j] == D_h(i, j, 0)
        ans = max(ans, memo_H[i][j] + memo_W[i][j] - 1)
print(ans)

Submission status: Runtime Error

Solution code:
#入力部
H, W = [int(i) for i in input().split()]

mymap = [] 　#mapの配列
myansmap = list(list(-1 for a in range(W)) for b in range(H))　#列方向を探索配列
myansmap2 = list(list(-1 for a in range(W)) for b in range(H))　#行方向を探索配列

#入力しながら，列方向を探索する
for i in range(H):
  myinput =  input()
  for j in range(W):
    if myinput[j] == '#':
      myansmap[i][j] = 0
    elif myinput[j] == '.':
      if myansmap [i][j] == -1 :
        mycnt = 0
        for m in range(j,W):
          if myinput[m] == '#':
            break
          mycnt += 1
      for k in range(j, m+1):
        myansmap[i][k] = mycnt
  mymap.append(myinput)

mymax = -99　#出力用変数

#行方向を探索する
for i in range(H):
  for j in range(W):
    #探索していない箇所について
    if myansmap2 [i][j] == -1:
      mycnt = 0
      for m in range(i,H):
        if myansmap[m][j] == 0:
          break
        mycnt += 1
      for k in range(i, m+1):
        if i > 0 and i < H or  j > 0 and i < W:
          myansmap2[k][j] = mycnt
        else: 
          myansmap2[k][j] = mycnt
    if myansmap[i][j] == 0:
      myansmap2[i][j] = 0

      
    if mymax < myansmap[i][j] + myansmap2[i][j]:
      mymax=myansmap[i][j] + myansmap2[i][j]

print(mymax-1)

Submission status: Runtime Error

Solution code:
H,W = list(map(int,input().split()))
MAP = [input() for i in range(H)]
cnt = [[[0,0] for w in range(W)] for h in range(H)]

for hdx,line in enumerate(MAP):
  wdx_start = 0
  for part in line.split("#"):
    for wdx in range(wdx_start,wdx_start+len(part)):
      cnt[hdx][wdx][0] = len(part)
    wdx_start += len(part)+1

for wdx,line in enumerate(["".join([s[i] for s in MAP]) for i in range(H)]):
  hdx_start = 0
  for part in line.split("#"):
    for hdx in range(hdx_start,hdx_start+len(part)):
      cnt[hdx][wdx][1] = len(part)
    hdx_start += len(part)+1

print(max([max([thing[0]+thing[1]-1 for thing in line]) for line in cnt]))

Submission status: Runtime Error

Solution code:
H,W = list(map(int,input().split()))
MAP = [input() for i in range(H)]
cnt = [[[0,0] for h in range(H)] for w in range(W)]

for wdx,line in enumerate(MAP):
  hdx_start = 0
  for part in line.split("#"):
    for hdx in range(hdx_start,hdx_start+len(part)):
      cnt[wdx][hdx][0] = len(part)
    hdx_start += len(part)+1

for hdx,line in enumerate(["".join([s[i] for s in MAP]) for i in range(W)]):
  wdx_start = 0
  for part in line.split("#"):
    for wdx in range(wdx_start,wdx_start+len(part)):
      cnt[wdx][hdx][1] = len(part)
    wdx_start += len(part)+1


print(max([max([thing[0]+thing[1]-1 for thing in line]) for line in cnt]))

Submission status: Runtime Error

Solution code:
#ABC129D-Lamp.py

#import list
from sys import stdin, setrecursionlimit
from functools import lru_cache

input = stdin.readline
setrecursionlimit(1000)

#constant
H, W = list(map(int,input().split()))
S = [input() for _ in range(H)]

#variable

#function
@lru_cache(maxsize=None)
def L(i,j):
    if S[i-1][j-1] == "#":
        return 0
    elif S[i-1][j-1] == ".":
        if j == 1:
            return 1
        else:
            return L(i,j-1) + 1

@lru_cache(maxsize=None)
def R(i,j):
    if S[i-1][j-1] == "#":
        return 0
    elif S[i-1][j-1] == ".":
        if j == W:
            return 1
        else:
            return R(i,j+1) + 1

@lru_cache(maxsize=None)
def U(i,j):
    if S[i-1][j-1] == "#":
        return 0
    elif S[i-1][j-1] == ".":
        if i == 1:
            return 1
        else:
            return U(i-1,j) + 1

@lru_cache(maxsize=None)
def D(i,j):
    if S[i-1][j-1] == "#":
        return 0
    elif S[i-1][j-1] == ".":
        if i == H:
            return 1
        else:
            return D(i+1,j) + 1

#class

#main function
def main():
    maxScore = 0
    for i in range(1,H+1):
        for j in range(1,W+1):
            score = L(i,j)+R(i,j)+U(i,j)+D(i,j)-3
            if score > maxScore:
                maxScore = score
    print(maxScore)


if __name__ == "__main__":
    main()

Submission status: Runtime Error

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

# H, W = 4, 6
board = []
L = [[0 for i in range(W)] for i in range(H)]
R = [[0 for i in range(W)] for i in range(H)]
U = [[0 for i in range(W)] for i in range(H)]
D = [[0 for i in range(W)] for i in range(H)]

# board = [['#', '.', '.', '#', '.', '.'], ['.', '.', '.', '.', '.', '#'], ['.', '.', '.', '.', '#', '.'], ['#', '.', '#', '.', '.', '.']]

# insert elements to the board
for i in range(H):
	a = list(input())
	board.append(a)


# high_score is output values
high_score = 0
	
# round robin
for h in range(H):
	for w in range(W):
		# print(h, w)
		# board put light is envolved
		score = 1
		# if not obstacle in board[h][w]
		if board[h][w] != "#":
			# DOWN
			for i in range(1, H):
				if h + i == W:
					break
				elif board[h + i][w] == "#":
					break
			score += i - 1
			D[h][w] = i - 1
			# print(D[h][w])
			
			# UP
			if h == 0 or board[h - 1][w] == "#":
				U[h][w] = 0
			else:
				U[h][w] = U[h - 1][w] + 1
			score += U[h][w]
			# print(U[h][w])
			
			# RIGHT
			for i in range(1, W):
				if w + i == W:
					break
				elif board[h][w + i] == "#":
					break
			score += i - 1
			R[h][w] = i - 1
			# print(R[h][w])
			
			# LEFT
			if w == 0 or board[h][w - 1] == "#":
				L[h][w] = 0
			else:
				L[h][w] = L[h][w - 1] + 1
			score += L[h][w]
			# print(L[h][w])
			
			# print(score)
			if score > high_score:
				high_score = score
				
print(high_score)

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 = [list(input().strip()) for _ in range(H)]

row_wise = list(map(f, grid))
col_wise = list(zip(*map(f, zip(*grid))))

ans = 0
for i in range(H):
    for j in range(W):
        ans = max(ans, row_wise[i][j] + col_wise[i][j] - 1)

# 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)

# print(row_wise)
# print(col_wise)

print(ans)

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python
 
import sys
import numpy as np

h,w = [ int(x) for x in sys.stdin.readline().split() ]
masu = np.ndarray( shape=(h,w),dtype='U1' )
for i in range(h):
    row = sys.stdin.readline()
    for j in range(w): masu[i][j]= str( row[j] )
#
# l, r
w1 = w - 1
l= np.ndarray( shape=(h,w),dtype=np.int32 )
r= np.ndarray( shape=(h,w),dtype=np.int32 )
for i in range(h):
    for j in range(w):
        if masu[i][j]=="#": l[i][j]= 0
        elif j==0: l[i][j]= 1
        else: l[i][j]= l[i][j-1] + 1
    #
for i in range(h)
    for j in range(w1,-1,-1):
        if masu[i][j]=="#": r[i][j]= 0
        elif j==w1: r[i][j]= 1
        else: r[i][j]= r[i][j+1] + 1
#
# u, d
h1= h - 1
u= np.ndarray( shape=(h,w),dtype=np.int32 )
d= np.ndarray( shape=(h,w),dtype=np.int32 )
for j in range(w):
    for i in range(h):
        if masu[i][j]=="#": u[i][j]= 0
        elif i==0: u[i][j]= 1
        else: u[i][j]= u[i-1][j] + 1
    #
for j in range(w):
    for i in range(h1,-1,-1):
        if masu[i][j]=="#": d[i][j]= 0
        elif i==h1: d[i][j]= 1
        else: d[i][j]= d[i+1][j] + 1
#
print( np.amax( l+r+u+d )-3 )

Submission status: Runtime Error

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

S = []
for _ in range(H):
    tmp = list(input())
    S.append(tmp)
    
import numpy as np

def count_light(Gs, h, w):
    Gc = np.empty((h,w))
    for i, gs in enumerate(Gs):
        count = 0
        for j, s in enumerate(gs):
            if s == '#':
                count = 0
                Gc[i][j] = 0
            else:
                count += 1
                Gc[i][j] = count

    return Gc

Gs1 = np.asarray(S)
Gn1 = count_light(Gs1, H, W)

Gs2 = np.rot90(Gs, k=1)
Gn2 = count_light(Gs2, W, H)

Gs3 = np.rot90(Gs2, k=1)
Gn3 = count_light(Gs3, H, W)

Gs4 = np.rot90(Gs3, k=1)
Gn4 = count_light(Gs4, W, H)

Gn2 = np.rot90(Gn2, k=-1)
Gn3 = np.rot90(Gn3, k=-2)
Gn4 = np.rot90(Gn4, k=-3)

Gsum = Gn1+Gn2+Gn3+Gn4
ans = int(np.max(Gsum)-3)
print(ans)

Submission status: Runtime Error

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

S = []
for _ in range(H):
    tmp = list(input())
    S.append(tmp)
    
import numpy as np

Gs = np.asarray(S)
Gs_ = np.rot90(Gs, k=1)

def count_light(Gs, h, w):
    Gc = np.empty((h,w))
    for i, gs in enumerate(Gs):
        count = 0
        gc = []
        for j, s in enumerate(gs):
            if s == '#':
                count = 0
                Gc[i][j] = 0
            else:
                count += 1
                Gc[i][j] = count

    Gn = np.empty((h,w))
    for i, gc in enumerate(Gc):
        count = -1
        gn = []
        for j, c in enumerate(reversed(gc)):
            if c == 0:
                count = -1
                Gn[i][j] = 0
            else:
                if count == -1:
                    count = c
                Gn[i][w-j-1]  = count

    return Gn

Gn = count_light(Gs, H, W)
Gn_ = count_light(Gs_, W, H)
Gn_ = np.rot90(Gn_, k=-1)

Gsum = Gn+Gn_
ans = np.max(Gsum)-1

        
print(int(ans))

Submission status: Runtime Error

Solution code:
H,W = map(int,input().split())
maze = [['#']*(W+2)]
for i in range(H):
    append_str = '#' + input() + '#'
    maze.append(list(append_str))
maze.append(['#']*(W+2))
L = [[0]*(W+2)]
for i in range(H+1):
    L.append([0]*(W+2))
import sys
sys.setrecursionlimit(10000000000)
import copy
R = copy.deepcopy(L)
U = copy.deepcopy(L)
D = copy.deepcopy(L)

for h in range(H+2):
    for w in range(W+2):
       if maze[h][w] == '.':
           L[h][w] = L[h][w-1]+1
           U[h][w] = U[h-1][w]+1
       if maze[h][W+2-w-1]=='.':
           R[h][W+2-w-1] = R[h][W+2-w]+1
       if maze[H+2-h-1][w]=='.':
           D[H+2-h-1][w] = D[H+2-h][w]+1
           
ans = -1
for h in range(H):
    for w in range(W):
        ans = max(ans,(L[h][w]+R[h][w]+U[h][w]+D[h][w]-3))
print(ans)

Submission status: Runtime Error

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

sq = [input() for _ in range(h)]
up = [[0] * (w + 2) for _ in range(h + 2)]
down = [[0] * (w + 2) for _ in range(h + 2)]
left = [[0] * (w + 2) for _ in range(h + 2)]
right = [[0] * (w + 2) for _ in range(h + 2)]

ans = 0

for i in range(1, h + 1):
    for j in range(1, w + 1):
        if sq[i][j] == '#':
            left[i][j] = 0
            up[i][j] = 0
        else:
            left[i][j] = left[i][j - 1] + 1
            up[i][j] = up[i - 1][j] + 1
for _i in range(h - 1, 0, -1):
    for _j in range(w - 1, 0, -1):
        if sq[_i][_j] == '#':
            right[_i][_j] = 0
            down[_i][_j] = 0
        else:
            right[_i][_j] = right[_i][_j + 1] + 1
            down[_i][_j] = down[_i + 1][_j] + 1

            temp = up[_i][_j] + down[_i][_j] + left[_i][_j] + right[_i][_j] 
            if temp > ans:
                ans = temp

print(ans - 3)

Submission status: Runtime Error

Solution code:
from collections import defaultdict


H, W = map(int, input().split())
mass = list()
for i in range(H):
    mass.append(input())

values_col = defaultdict(int)
values_row = defaultdict(int)

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

ind = 0
for i, m_row in enumerate(mass):
    ind += 1
    for j, chr in enumerate(mass[i]):
        if chr == '#':
            ind += 1
        else:
            values_row[ind] += 1
            ind_row[i][j] = ind

# print('ROW')
# for i in range(H):
#     for j in range(W):
#         print(values_row[ind_row[i][j]], end=' ')
#     print()

ind = 0
for j in range(W):
    ind += 1
    for i in range(H):
        chr = mass[i][j]
        if chr == '#':
            ind += 1
        else:
            values_col[ind] += 1
            ind_col[i][j] = ind

# print('COL')
# for i in range(H):
#     for j in range(W):
#         print(values_col[ind_col[i][j]], end=' ')
#     print()

ans = 0
for i in range(H):
    for j in range(W):
        ans = max(ans, values_row[ind_row[i][j]] + values_col[ind_col[i][j]] - 1)
print(ans)

Submission status: Runtime Error

Solution code:
H, W = map( int, input().split())
d = dict()
S = [["#"]*(W+2)]+[ "#"+input()+"#" for _ in range(H)]+ [["#"]*(W+2)]
H += 2
W += 2
L = [[0]*(W+2) for _ in range(H+2)]
R = [[0]*(W+2) for _ in range(H+2)]
D = [[0]*(W+2) for _ in range(H+2)]
U = [[0]*(W+2) for _ in range(H+2)]
cnt = 0
for i in range(W):
    d[(0,j)] = 1
    d[(H-1,j)] = 1
for i in range(1,H-1):
    for j in range(W):
        if S[i][j] == "#":
            d[(i,j)] = 1
            cnt = 0
        else:
            d[(i,j)] = 0
            cnt += 1
            R[i][j] = cnt
            
for i in range(1,H-1):
    for j in range(W-1,-1,-1):
        if d[(i,j)] == 1:
            cnt = 0
        else:
            cnt += 1
            L[i][j] = cnt

for j in range(1,W-1):
    for i in range(H):
        if  d[(i,j)] == 1:
            cnt = 0
        else:
            cnt += 1
            D[i][j] = cnt

for j in range(1,W-1):
    for i in range(H-1,-1,-1):
        if d[(i,j)] == 1:
            cnt = 0
        else:
            cnt += 1
            U[i][j] = cnt

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

Submission status: Runtime Error

Solution code:
import numpy as np
words = lambda t : list(map(t, input().split()))



h,w = words(int)
wq = [0] * w

grid = []
for i in range(h):
    grid.append(list(input()))

ans = 0
for i in range(h):
    j = 0
    while j < w:
        #print(i,j, grid[i][j])
        if grid[i][j] == '#':
            wq[j] = 0
            j+=1
            continue
        k = 0
        while j+k < w:
            if grid[i][j+k] == '.':
                k += 1
            else:
                break
        #print(i,j,k)
        if k + h > ans:
            for x in range(j,j+k):
                vplus = 0
                if not wq[x] == 0:
                    vplus = wq[x]
                else:
                    for vi in range(i-1,-1,-1):
                        if grid[vi][x] == '#':
                            break
                        else:
                            vplus += 1
                    for vi in range(i+1,h):
                        if grid[vi][x] == '#':
                            break
                        else:
                            vplus += 1
                ans = max(ans, vplus+k)
                wq[x] = vplus
        j += k
print(ans)

Submission status: Runtime Error

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

grids = []
for _ in range(H):
    grids.append(input())

grids = np.array(grids)
t_grids = grids.T
hr_scores = np.array([[-1] * W for _ in range(H)])
vr_scores = np.array([[-1] * H for _ in range(W)])

for h in range(H):
    cnt_hr = 0
    cnt_vr = 0
    start_hr = 0
    start_vr = 0
    for w in range(W):
        if grids[h][w] == '.':
            cnt_hr += 1
        else:
            hr_scores[h, w] = 0
            hr_scores[h, start_hr: w] = cnt_hr
            start_hr = w + 1
            cnt_hr = 0
        if t_grids[w][h] == '.':
            cnt_vr += 1
        else:
            vr_scores[h, w] = 0
            vr_scores[h, start_vr: w] = cnt_vr
            start_vr = w + 1
            cnt_vr = 0
    if cnt_hr:
        hr_scores[h, start_hr: w + 1] = cnt_hr
    if cnt_vr:
        vr_scores[h, start_vr: w + 1] = cnt_vr
        
print(max((hr_scores + vr_scores.T).max() - 1, 0))

Submission status: Runtime Error

Solution code:
import numpy as np

H, W = map(int, input().split())

grids = []
for _ in range(H):
    grids.append(input())

grids = np.array(grids)
t_grids = grids.T
hr_scores = np.array([[-1] * W for _ in range(H)])
vr_scores = np.array([[-1] * H for _ in range(W)])

for h in range(H):
    cnt_hr = 0
    cnt_vr = 0
    start_hr = 0
    start_vr = 0
    for w in range(W):
        if grids[h][w] == '.':
            cnt_hr += 1
        else:
            hr_scores[h, w] = 0
            hr_scores[h, start_hr: w] = cnt_hr
            start_hr = w + 1
            cnt_hr = 0
        if t_grids[w][h] == '.':
            cnt_vr += 1
        else:
            vr_scores[h, w] = 0
            vr_scores[h, start_vr: w] = cnt_vr
            start_vr = w + 1
            cnt_vr = 0
    if cnt_hr:
        hr_scores[h, start_hr: w + 1] = cnt_hr
    if cnt_vr:
        vr_scores[h, start_vr: w + 1] = cnt_vr
        
print(max((hr_scores + vr_scores.T).max() - 1, 0))

Submission status: Runtime Error

Solution code:
import numpy as np

H, W = map(int, input().split())

grids = []
for _ in range(H):
    grids.append(input())

hr_scores = []
vr_scores = []

for h in range(H):
    cnt = 0
    start_w = 0
    lis = []
    for w in range(W):
        if grids[h][w] == '.':
            cnt += 1
        else:
            lis += [cnt] * (w - start_w) + [0]
            start_w = w + 1
            cnt = 0
    if cnt:
        lis += [cnt] * (w - start_w + 1)
    hr_scores.append(lis)

for w in range(W):
    cnt = 0
    start_h = 0
    lis = []
    for h in range(H):
        if grids[h][w] == '.':
            cnt += 1
        else:
            lis += [cnt] * (h - start_h) + [0]
            start_h = h + 1
            cnt = 0
    if cnt:
        lis += [cnt] * (h - start_h + 1)
    vr_scores.append(lis)

hr_scores = np.array(hr_scores)
vr_scores = np.array(vr_scores)
print(max((hr_scores + vr_scores).max() - 1, 0))

Submission status: Runtime Error

Solution code:
import sys
import numpy as np


def chain(l, i):
    return 0 if l[i] == 1 else chain(l, i + 1) + 1


def main():
    h, w = [int(x) for x in input().split()]
    board = [[1 for i in range(w + 2)]]
    for i in range(h):
        board.append([1 if c == '#' else 0 for c in "#" + input() + "#"])
    board.append([1 for i in range(w + 2)])
    boardt = np.array(board).T.tolist()
    ansrow = []
    anscol = []
    for i, line in enumerate(board):
        ansrow.append([0])
        for j in range(1, w + 2):
            ansrow[i].append(ansrow[i][j - 1] if line[j] == 0 and line[j - 1] == 0 else chain(line, j))
    for j, linet in enumerate(boardt):
        anscol.append([0])
        for i in range(1, h + 2):
            anscol[j].append(anscol[j][i - 1] if linet[i] == 0 and linet[i - 1] == 0 else chain(linet, i))
    print(np.amax(np.array(ansrow) + np.array(anscol).T - 1))


main()

Submission status: Runtime Error

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


class UnionFind:
    def __init__(self, size):
        self.UF = list(range(size))
        self.SIZE = [1] * size  # 0-indexed

    def find(self, x):
        UF = self.UF
        find = self.find
        if UF[x] != x:
            UF[x] = find(UF[x])
        return UF[x]

    def unite(self, x, y):
        is_same = self.is_same
        find = self.find
        SIZE = self.SIZE
        UF = self.UF
        if not is_same(x, y):
            X, Y = find(x), find(y)
            SX, SY = SIZE[X], SIZE[Y]
            if SX > SY:
                m = UF[X] = Y
            else:
                m = UF[Y] = X
            SIZE[m] = SX + SY
            SIZE[X + Y - m] = 0

    def is_same(self, x, y):
        find = self.find
        return find(x) == find(y)

    def scan_uf(self):
        find = self.find
        length = len(self.UF)
        for i in range(length):
            find(i)

    def size(self, x):
        return self.SIZE[self.find(x)]


score = [[0 for _ in range(W)] for _ in range(H)]
UF1 = UnionFind(H * W)
for h in range(H):
    w = 0
    while w < W:
        if S[h][w] == '.':
            w0 = w
            while w < W and S[h][w] == '.':
                UF1.unite(W * h + w, W * h + w0)
                w += 1
        else:
            w += 1
UF2 = UnionFind(H * W)
for w in range(W):
    h = 0
    while h < H:
        if S[h][w] == '.':
            h0 = h
            while h < H and S[h][w] == '.':
                UF2.unite(W * h + w, W * h0 + w)
                h += 1
        else:
            h += 1
ans = -1
for h in range(H):
    for w in range(W):
        ans = max([ans, UF1.size(W * h + w) + UF2.size(W * h + w) - 1])
print(ans)

Submission status: Runtime Error

Solution code:
#include <bits/stdc++.h>
using namespace std;
int H, W;

int main() {
    cin >> H >> W;
    vector<vector<int>> a(H + 1, vector<int>(W + 1));
    for(int i = 0; i < W + 1; i++){
        a.at(H).at(i) = 0;
    }
    for(int j = 0; j < H; j++){
        string str;
        cin >> str;
        a.at(j).at(W) = 0;
        for(int i = 0; i < W; i++){
            if(str.at(i) == '.')
                a.at(j).at(i) = 1;
            else
                a.at(j).at(i) = 0;
        }
    }

    //横方向
    for(int j = 0; j < H; j++){
        int prev = 0;
        int start = 0;
        for(int i = 0; i < W + 1; i++){
            if (a.at(j).at(i) > 0){
                if(prev == 0){
                    start = i;
                    prev = 1;
                }
            }else{
                if(prev == 1){
                    int num = i - start;
                    for(int k = start; k < i; k++){
                        a.at(j).at(k) = num;
                    }
                    prev = 0;
                }
            }
        }
    }

    //縦方向
    for(int i = 0; i < W; i++){
        int prev = 1;
        int start = 0;
        for(int j = 0; j < H + 1; j++){
            if (a.at(j).at(i) > 0){
                if(prev == 0){
                    start = j;
                    prev = 1;
                }
            }else{
                if(prev == 1){
                    int num = j - start;
                    for(int k = start; k < j; k++){
                        a.at(k).at(i) += num - 1;
                    }
                    prev = 0;
                }
            }
        }
    }

    int ans = 0;
    for(int j = 0; j < H; j++){
        int m1 = *max_element(a.at(j).begin(), a.at(j).end());
        ans = max(ans, m1);
    }
    cout << ans << endl;
}

Submission status: Runtime Error

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

a = list(range(h))
for i in range(h):
  a[i] = list(map(str,input()))
  a[i].append("#")
  a[i].insert(0,"#")
a.append(["#"]*(w+2))
a.insert(0,(["#"]*(w+2)))

c = 0
c_ = 0
hi = []
wi = []
for i,i_ in range(h+2),range(w+2):
  for j,j_ in range(w+2),range(h+2):
    if a[i][j] == "#":
      wi.append(c)
      c = 0
    if a[i][j] == ".":
      c += 1
for i in range(w+2):
  for j in range(h+2):    
    if a[j][i] == "#":
      hi.append(c_)
      c_ = 0
    if a[j][i] == ".":
      c_ += 1
print(max(hi)+max(wi)-1)

Submission status: Runtime Error

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

a = list(range(h))
for i in range(h):
  a[i] = list(map(str,input()))
  a[i].append("#").insert(0,"#")
a.append(["#"]*(w+2))
a.insert(0,(["#"]*(w+2)))

c = 0
c_ = 0
hi = []
wi = []
for i in range(h+2):
  for j in range(w+2):
    if a[i][j] == "#":
      wi.appned(c)
      c = 0
    if a[i][j] == ".":
      c += 1
for i in range(w+2):
  for j in range(h+2):    
    if a[j][i] == "#":
      hi.appned(c_)
      c_ = 0
    if a[j][i] == ".":
      c_ += 1
print(max(hi)+max(wi))