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: Accepted

Solution code:
# -*- coding:utf-8 -*-
import numpy as np


def solve():
    H, W = list(map(int, input().split()))
    grid = []
    for i in range(H):
        s = input()
        grid.append(list(s))
    grid = (np.array(grid) == ".") * 1  # ランプを置ける:1, 置けない:0

    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 w in range(W):
        if w == 0:
            L[:, w] = grid[:, w]
        else:
            L[:, w] = (L[:, w-1]+1) * grid[:, w]

    # 右
    for w in range(W-1, -1, -1):
        if w == W-1:
            R[:, w] = grid[:, w]
        else:
            R[:, w] = (R[:, w+1]+1) * grid[:, w]

    # 上
    for h in range(H):
        if h == 0:
            U[h] = grid[h]
        else:
            U[h] = (U[h-1]+1) * grid[h]

    # 下
    for h in range(H-1, -1, -1):
        if h == H-1:
            D[h] = grid[h]
        else:
            D[h] = (D[h+1]+1) * grid[h]

    # 答え
    ans = np.max(L+R+U+D-3)
    print(ans)


if __name__ == "__main__":
    solve()

Submission status: Accepted

Solution code:
#%%
import numpy as np

h, w = map(int, input().split())
s = [[] for _ in range(h)]
for i in range(h):
    s[i] = list(input())
s_0 = np.array(s)
s_90 = np.rot90(s_0)
s_180 = np.rot90(s_90)
s_270 = np.rot90(s_180)

c_0 = np.zeros(h*w).reshape(h,-1)
c_0[s_0 == '.'] = 1
c_90 = np.zeros(h*w).reshape(w,-1)
c_90[s_90 == '.'] = 1
c_180 = np.zeros(h*w).reshape(h,-1)
c_180[s_180 == '.'] = 1
c_270 = np.zeros(h*w).reshape(w,-1)
c_270[s_270 == '.'] = 1


for j in range(1, w):
    c_0[:, j] += c_0[:, j-1] * c_0[:, j]
#print(c_0)

for j in range(1, h):
    c_90[:, j] += c_90[:, j-1] * c_90[:, j]
c_90 = np.rot90(np.rot90(np.rot90(c_90)))
#print(c_90)

for j in range(1, w):
    c_180[:, j] += c_180[:, j-1] * c_180[:, j]
c_180 = np.rot90(np.rot90(c_180))
#print(c_180)

for j in range(1, h):
    c_270[:, j] += c_270[:, j-1] * c_270[:, j]
c_270 = np.rot90(c_270)
#print(c_270)

c = c_0 + c_90 + c_180 + c_270 - 3
print(int(c.max()))

Submission status: Accepted

Solution code:
H,W=map(int,input().split())
s=[]
for i in range(H):
    si=[]
    Si=input()
    for j in range(W):
        si.append(Si[j]=='.')
    s.append(si)

# 左に照らした場合 行ごとに見てゆく
L=[[0 for j in range(W)] for i in range(H)]
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

# 右に照らした場合 行ごとに見てゆく
R=[[0 for j in range(W)] for i in range(H)]
for i in range(H):
    for j in reversed(range(W)):
        if s[i][j]:
            if j==W-1:
                R[i][j]=1
            else:
                R[i][j]=R[i][j+1]+1

# 上に照らした場合 列ごとに見てゆく
U=[[0 for j in range(W)] for i in range(H)]
for j in range(W):
    for i in range(H):
        if s[i][j]:
            if i==0:
                U[i][j]=1
            else:
                U[i][j]=U[i-1][j]+1

# 下に照らした場合 列ごとに見てゆく
D=[[0 for j in range(W)] for i in range(H)]
for j in range(W):
    for i in reversed(range(H)):
        if s[i][j]:
            if i==H-1:
                D[i][j]=1
            else:
                D[i][j]=D[i+1][j]+1

ans=0
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)

Submission status: Accepted

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

# 上下左右に余分に1マスとっとく
square = [[0 for _ in range(W)] for _ in range(H)]

for row in range(H):
	S = list(map(str, input()))
	for column in range(W):
		if S[column] == "#":
			# 下駄をはかせるの忘れない
			square[row][column] = -1
			
for row in range(H):
	done = [False for _ in range(W)]
	for column in range(W):
		if square[row][column] == -1: continue
		if done[column]: continue
		l = 1
		while column + l <= W - 1:
			if square[row][column + l] == -1: break
			l += 1
		for i in range(column, column + l):
			square[row][i] += l
			done[i] = True
			
for column in range(W):
	done = [False for _ in range(H)]
	for row in range(H):
		if square[row][column] == -1: continue
		if done[row]: continue
		l = 1
		while row + l <= H - 1:
			if square[row + l][column] == -1: break
			l += 1
		for i in range(row, row + l):
			square[i][column] += l
			done[i] = True

ret = 0			
for row in range(H):
	for column in range(W):
		ret = max(ret, square[row][column] - 1)
		
		
print(ret)

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

import numpy as np

H,W = map(int,readline().split())
floor = np.frombuffer(read(),dtype='S1').reshape(H,-1)[:,:W] == b'.'

score = np.zeros((H,W),np.int32)

x = np.zeros((H,W),np.int32)
for n in range(1,H):
    x[n] = (1+x[n-1])*floor[n-1]
score += x

x[:] = 0
for n in range(H-1,0,-1):
    x[n-1] = (1+x[n])*floor[n]
score += x

x[:] = 0
for n in range(1,W):
    x[:,n] = (1+x[:,n-1])*floor[:,n-1]
score += x

x[:] = 0
for n in range(W-1,0,-1):
    x[:,n-1] = (1+x[:,n])*floor[:,n]
score += x

score *= floor
answer = score.max() + 1
print(answer)

Submission status: Accepted

Solution code:
import numpy as np

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

R = np.zeros((H, W), dtype=int)
L = np.zeros((H, W), dtype=int)
U = np.zeros((H, W), dtype=int)
D = np.zeros((H, W), dtype=int)

for i in range(H):
    U[i] = (U[i-1] + 1) * S[i]
    D[-i-1] = (D[-i] + 1) * S[-i-1]

for i in range(W):
    L[:, i] = (L[:, i-1] + 1) * S[:, i]
    R[:, -i-1] = (R[:, -i] + 1) * S[:, -i-1]

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

Submission status: Accepted

Solution code:
def slove():
    import sys
    input = sys.stdin.readline
    h, w = list(map(int, input().rstrip('\n').split()))
    s = [list(str(input().rstrip('\n'))) for _ in range(h)]
    u = [[0] * w for _ in range(h)]
    d = [[0] * w for _ in range(h)]
    l = [[0] * w for _ in range(h)]
    r = [[0] * w for _ in range(h)]
    for i in range(h):
        for j in range(w):

            if i == 0:
                u[i][j] += 1 if s[i][j] != "#" else 0
                d[-i-1][j] += 1 if s[-i-1][j] != "#" else 0
            else:
                u[i][j] += 1 + u[i-1][j] if s[i][j] != "#" else 0
                d[-i-1][j] += 1 + d[-i][j] if s[-i-1][j] != "#" else 0

            if j == 0:
                l[i][j] += 1 if s[i][j] != "#" else 0
                r[i][-j-1] += 1 if s[i][-j-1] != "#" else 0
            else:
                l[i][j] += 1 + l[i][j-1] if s[i][j] != "#" else 0
                r[i][-j-1] += 1 + r[i][-j] if s[i][-j-1] != "#" else 0

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


if __name__ == '__main__':
    slove()

Submission status: Accepted

Solution code:
def main():
    from sys import stdin
    from builtins import range

    readline = stdin.readline

    H, W = map(int, readline().split())
    S = [readline()[:-1] + '#' for _ in range(H)]

    S.append('#' * W)
    ft = [[i] * i for i in range(100)]
    yoko = [[0] * W for _ in range(H)]
    for i in range(H):
        start = -1
        si = S[i]
        yokoi = yoko[i]
        for j in range(W + 1):
            if si[j] == '#':
                if start != -1:
                    t = j - start
                    if t < 100:
                        yokoi[start:j] = ft[t]
                    else:
                        yokoi[start:j] = [t] * t
                    start = -1
            else:
                if start == -1:
                    start = j

    result = 0
    for i in range(W):
        start = -1
        for j in range(H + 1):
            if S[j][i] == '#':
                if start != -1:
                    t = yoko_max + j - start - 1
                    if t > result:
                        result = t
                    start = -1
            else:
                yji = yoko[j][i]
                if start == -1:
                    start = j
                    yoko_max = yji
                else:
                    if yji > yoko_max:
                        yoko_max = yji
    print(result)


main()

Submission status: Accepted

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

L = [input() for i in range(H)]
count = [i*W for i in [[0]]*H]
for i in range(H):
    start = 0
    end = 1
    seq = 0
    for j in range(W):
        if L[i][j]=='.':
            seq+=1
            end+=1
            if j==W-1:
                count[i][start:W]=[seq for k in range(W-start)]
            
        else:
            end=j
            count[i][start:end]=[seq for k in range(end-start)]
            if not W-1==j:
                start=j+1
            seq=0
L = list(map(list, (zip(*L))))
count = list(map(list, (zip(*count))))
for i in range(W):
    start = 0
    end = 1
    seq = 0
    for j in range(H):
        if L[i][j]=='.':
            seq+=1
            end+=1
            if j==H-1:
                for n in range(H-start):
                    count[i][start+n]+=seq
        else:
            end=j
            for n in range(end-start):
                count[i][start+n]+=seq
            if not H-1==j:
                start=j+1
            seq=0
num_max=0
for i in range(W):
    for j in range(H):
        if num_max<count[i][j]:
            num_max=count[i][j]
print(num_max-1)

Submission status: Accepted

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

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

    # Lをカウント
    for i in range(H):
        cnt = 0
        for j in range(W):
            if S[i][j] == '#':
                cnt = 0
                continue
            else:
                cnt += 1
                L[i][j] = cnt

    for i in range(H):
        cnt = 0
        for j in range(W-1, -1, -1):
            if S[i][j] == '#':
                cnt = 0
                continue
            else:
                cnt += 1
                R[i][j] = cnt

    for j in range(W):
        cnt = 0
        for i in range(H):
            if S[i][j] == '#':
                cnt = 0
                continue
            else:
                cnt += 1
                U[i][j] = cnt

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

    ans = 0
    for i in range(H):
        for j in range(W):
            if S[i][j] == '#':
                continue
            tmp = L[i][j] + R[i][j] + U[i][j] + D[i][j] - 3
            ans = max(ans,tmp)

    print(ans)

main()

Submission status: Accepted

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

    left = [[0] * W for _ in range(H)]
    right = [[0] * W for _ in range(H)]
    up = [[0] * W for _ in range(H)]
    down = [[0] * W for _ in range(H)]

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

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

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

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

    ans = 0
    for i in range(H):
        for j in range(W):
            if S[i][j] == '#':
                continue
            ans = max(ans, left[i][j] + right[i][j] + up[i][j] + down[i][j] - 3)

    print(ans)

main()

Submission status: Accepted

Solution code:
import numpy as np

h,w=map(int,input().split())
s=np.array([[(1 if x=='.' else 0) for x in list(input())] for y in range(h)])

r=np.zeros((h,w),dtype=int)
l=np.zeros((h,w),dtype=int)
d=np.zeros((h,w),dtype=int)
u=np.zeros((h,w),dtype=int)

l[:,0] = s[:,0]
r[:,w-1] = s[:,w-1]
for i in range(1,w):
  l[:,i] = (l[:,i-1]+1) * s[:,i]
  r[:,w-i-1] = (r[:,w-i]+1) * s[:,w-i-1]

u[0]=s[0]
d[h-1]=s[h-1]
for i in range(1,h):
  u[i] = (u[i-1]+1) * s[i]
  d[h-i-1] = (d[h-i]+1) * s[h-i-1]

print(((l+r+u+d).max()-3))

Submission status: Accepted

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

for h in range(H):
    start = 0
    while start < W:
        while start < W and S[h][start] == '#':
            start += 1
        end = start
        while end < W and S[h][end] == '.':
            end += 1
        for i in range(start,end):
            A[h][i] += end - start
        start = end

for w in range(W):
    start = 0
    while start < H:
        while start < H and S[start][w] == '#':
            start += 1
        end = start
        while end < H and S[end][w] == '.':
            end += 1
        for i in range(start,end):
            A[i][w] += end - start
        start = end

ans = max(max(max(A[i]) for i in range(H)) - 1, 0)
print(ans)

Submission status: Accepted

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

R = np.zeros((H,W),dtype = int)
L = np.zeros((H,W),dtype = int)
U = np.zeros((H,W),dtype = int)
D = np.zeros((H,W),dtype = int)

for i in range(H):
    U[i] = (U[i - 1] + 1) *s[i]
    D[- i - 1] = (D[-i] + 1) * s[-i-1]
for i in range(W):
    L[:,i] = (L[:,i-1] + 1) * s[:,i]
    R[:,-1-i] = (R[:,-i] + 1) * s[:,-i-1]
print(np.max(L+R+U+D - 3))

Submission status: Accepted

Solution code:
H,W = map(int,input().split())
height, width_max, ans = [0] * (W+1), [0] * (W+1), 0
for i in range(H):
    s = input() + '#'
    length = 0
    for j in range(W+1):
        if s[j] == '.':
            length += 1
            height[j] += 1
        else:
            if length > 0:
                for k in range(j-length, j):
                    if width_max[k] < length:
                        width_max[k] = length
                length = 0
            if height[j] > 0:
                temp = width_max[j] + height[j] - 1
                if ans < temp:
                    ans = temp
                width_max[j], height[j] = 0, 0
for j in range(W):
    if height[j] > 0:
        temp = width_max[j] + height[j] - 1
        if ans < temp:
            ans = temp
print(ans)

Submission status: Accepted

Solution code:
import numpy as np
H, W = map(int, input().split())
S = np.array([list(input()) for i in range(H)])=="."

R = np.zeros((H,W), dtype=int)
L = np.zeros((H,W), dtype=int)
U = np.zeros((H,W), dtype=int)
D = np.zeros((H,W), dtype=int)
for i in range(H):
  U[i]= (U[i-1]+1)*S[i]
  D[-i-1]= (D[-i]+1)*S[-1-i]
for i in range(W):
  L[:,i]= (L[:,i-1]+1)*S[:,i]
  R[:,-1-i]= (R[:,-i]+1)*S[:,-i-1]
print (np.max(L+R+U+D-3))

Submission status: Accepted

Solution code:
from functools import reduce
import sys
import numpy as np


mod = 10 ** 9 + 7
buffer = sys.stdin.buffer
h, w = map(int, buffer.readline().split())
s = np.frombuffer(buffer.read(h*(w+1)), dtype='B') == ord('.')
s = s.reshape((h, w+1))[:, :-1]
l = np.empty((h, w), dtype='i4')
r = np.empty((h, w), dtype='i4')
u = np.empty((h, w), dtype='i4')
d = np.empty((h, w), dtype='i4')
l[:, 0] = s[:, 0]
for i in range(1, w):
    l[:, i] = (l[:, i-1] + 1) * s[:, i]
r[:, -1] = s[:, -1]
for i in range(1, w):
    r[:, -1-i] = (r[:, -i] + 1) * s[:, -1-i]
u[0] = s[0]
for i in range(1, h):
    u[i] = (u[i-1] + 1) * s[i]
d[-1] = s[-1]
for i in range(1, h):
    d[-1-i] = (d[-i] + 1) * s[-1-i]
score = l + r + u + d - 3
print(int(score.max()))

Submission status: Accepted

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

s = ["#"*(w+2)]

for _ in range(h):
    inpt = input()
    s.append("#"+inpt+"#")
s.append("#"*(w+2))

dp1 = [[0 for j in range(w+2)] for i in range(h+2)]
dp2 = [[0 for j in range(w+2)] for i in range(h+2)]

dp3 = [[0 for j in range(w+2)] for i in range(h+2)]
dp4 = [[0 for j in range(w+2)] for i in range(h+2)]

for i in range(1,h+1):
    for j in range(1,w+1):
        if s[i][j] != "#":
            dp1[i][j] = dp1[i-1][j] + 1
            dp3[i][j] = dp3[i][j-1] + 1
        if s[h+1-i][w+1-j] != "#":
            dp2[h+1-i][w+1-j] = dp2[h+1-i+1][w+1-j]+1
            dp4[h+1-i][w+1-j] = dp4[h+1-i][w+1-j+1]+1
            
dp5 = [[dp1[i][j]+dp2[i][j]+dp3[i][j]+dp4[i][j]-3 for j in range(w+2)] for i in range(h+2)]
mx = 0

for i in range(h+2):
    mx = max(mx,max(dp5[i]))
print(mx)

Submission status: Accepted

Solution code:
import sys
input=sys.stdin.readline

def main():
    H,W = map(int, input().split())
    
    S = []
    for _ in range(H):
        S.append(input().strip())
 
    u = [[0]*W for _ in range(H)]
    d = [[0]*W for _ in range(H)]
    l = [[0]*W for _ in range(H)]
    r = [[0]*W for _ in range(H)]
    for y in range(H):
        for x in range(W):
            if S[y][x] == "#":
                u[y][x] = l[y][x] = 0
            else:
                u[y][x] = 1 if y == 0 else u[y-1][x] + 1
                l[y][x] = 1 if x == 0 else l[y][x-1] + 1
    for y in range(H-1,-1,-1):
        for x in range(W-1,-1,-1):
            if S[y][x] == "#":
                d[y][x] = r[y][x] = 0
            else:
                d[y][x] = 1 if y == H-1 else d[y+1][x] + 1
                r[y][x] = 1 if x == W-1 else r[y][x+1] + 1
 
    ans = 0
    for y in range(H):
        for x in range(W):
            ans = max(ans, u[y][x] + d[y][x] + l[y][x] + r[y][x] - 3)
            
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def slove():
    import sys
    input = sys.stdin.readline
    h, w = list(map(int, input().rstrip('\n').split()))
    s = [list(str(input().rstrip('\n'))) for _ in range(h)]
    U = [[0] * w for _ in range(h)]
    D = [[0] * w for _ in range(h)]
    R = [[0] * w for _ in range(h)]
    L = [[0] * w for _ in range(h)]

    for i in range(h):
        for j in range(w):
            if i == 0:
                U[i][j] = 1 if s[i][j] != "#" else 0
                D[-i-1][j] = 1 if s[-i-1][j] != "#" else 0
            else:
                U[i][j] = 1 + U[i-1][j] if s[i][j] != "#" else 0
                D[-i-1][j] = 1 + D[-i][j] if s[-i-1][j] != "#" else 0
            if j == 0:
                L[i][j] = 1 if s[i][j] != "#" else 0
                R[i][-j-1] = 1 if s[i][-j-1] != "#" else 0
            else:
                L[i][j] = 1 + L[i][j-1] if s[i][j] != "#" else 0
                R[i][-j-1] = 1 + R[i][-j] if s[i][-j-1] != "#" else 0
    m_c = 0
    for i in range(h):
        for j in range(w):
            m_c = max(m_c, U[i][j] + D[i][j] + R[i][j] + L[i][j] - 3)
    print(m_c)


if __name__ == '__main__':
    slove()

Submission status: Accepted

Solution code:
import numpy as np
h,w = map(int,input().split())
S = np.array([list(input()) for _ in range(h)])=="."
D = np.zeros((h,w),dtype = int)
U = np.zeros((h,w),dtype = int)
L = np.zeros((h,w),dtype = int)
R = np.zeros((h,w),dtype = int)
for i in range(h):
  U[i]= (U[i-1]+1)*S[i]
  D[-i-1]= (D[-i]+1)*S[-1-i]
for i in range(w):
  L[:,i]= (L[:,i-1]+1)*S[:,i]
  R[:,-1-i]= (R[:,-i]+1)*S[:,-i-1]
print(np.max(U+D+R+L)-3)

Submission status: Accepted

Solution code:
#D
w,h=map(int,input().split())
s=[input() for i in range(w)]
t=[[[],[]] for j in range(w)]
for i in range(w):
    k=0
    for j in range(h):
        if s[i][j]==".":
            k+=1
        else:
            t[i][0]+=[k for _ in range(k)]+[0]
            k=0
    t[i][0]+=[k for _ in range(k)]
for i in range(h):
    k=0
    for j in range(w):
        if s[j][i]==".":
            k+=1
        else:
            for l in range(1,k+1):
                t[j-l][1]+=[k]
            t[j][1]+=[0]
            k=0
    for l in range(1,k+1):
        t[w-l][1]+=[k]
answer=0
for i in range(w):
    for j in range(h):
        answer=max(t[i][0][j]+t[i][1][j],answer)
print(answer-1)

Submission status: Accepted

Solution code:
def slove():
    import sys
    input = sys.stdin.readline
    h, w = list(map(int, input().rstrip('\n').split()))
    s = [list(str(input().rstrip('\n'))) for _ in range(h)]

    U = [[0] * w for _ in range(h)]
    D = [[0] * w for _ in range(h)]
    R = [[0] * w for _ in range(h)]
    L = [[0] * w for _ in range(h)]

    b = True
    for i in range(h):
        for j in range(w):
            if b:
                U[i][j] = 1 if s[i][j] != "#" else 0
                D[-i - 1][j] = 1 if s[-i - 1][j] != "#" else 0
                R[i][-j - 1] = 1 if s[i][-j - 1] != "#" else 0
                L[i][j] = 1 if s[i][j] != "#" else 0
                b = False
            else:
                U[i][j] = 1 + U[i-1][j] if s[i][j] != "#" else 0
                D[-i-1][j] = 1 + D[-i][j] if s[-i-1][j] != "#" else 0
                R[i][-j-1] = 1 + R[i][-j] if s[i][-j-1] != "#" else 0
                L[i][j] = 1 + L[i][j-1] if s[i][j] != "#" else 0
    mt = 0
    for i in range(h):
        for j in range(w):
            mt = max(mt, U[i][j] + D[i][j] + R[i][j] + L[i][j] - 3)
    print(mt)


if __name__ == '__main__':
    slove()

Submission status: Accepted

Solution code:
t,*grid = open(0)
h,w = map(int,t.split())
L,R,U,D = eval("[[0]*(w+2) for _ in range(h+2)],"*4)
for y in range(h):
	for x in range(w):
		if grid[y][x]==".":
			L[y+1][x+1] = L[y+1][x]+1
		if grid[y][w-x-1]==".":
			R[y+1][w-x] = R[y+1][w-x+1]+1
for x in range(w):
	for y in range(h):
		if grid[y][x]==".":
			U[y+1][x+1] = U[y][x+1]+1
		if grid[h-y-1][x]==".":
			D[h-y][x+1] = D[h-y+1][x+1]+1
print(max(L[y][x] + R[y][x] + U[y][x] + D[y][x] -3 for y in range(1,h+1) for x in range(1,w+1)))

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    a,b,c = LI()
    ans = 10 ** 5
    ans = min(ans, a + b)
    ans = min(ans, a + c)
    ans = min(ans, c + b)
    print(ans)
    return

#B
def B():
    n = II()
    w = LI()
    ans = inf
    for i in range(n):
        ans = min(ans, abs(sum(w[:i]) - sum(w[i:])))
    print(ans)
    return

#C
def C():
    n, m = LI()
    a = IR(m)+[inf]
    dp = [0] * (n + 3)
    dp[0] = 1
    for i in range(n + 1):
        if a[bisect_left(a, i + 1)] != i + 1:
            dp[i + 1] += dp[i] % mod
        if a[bisect_left(a, i + 2)] != i + 2:
            dp[i + 2] += dp[i] % mod
    print(dp[n] % mod)
    return

#D
def D():
    h, w = LI()
    s = SR(h)
    dp = [[0] * w for _ in range(h)]
    for x in range(w):
        for y in range(h):
            if s[y][x] == ".":
                dp[y][x] += 1
    for y in range(h):
        x = 0
        q = 0
        while 0 <= x < w:
            if s[y][x] == ".":
                dp[y][x] += q
                q += 1
            else:
                q = 0
            x += 1
        x = w - 1
        q = 0
        while 0 <= x < w:
            if s[y][x] == ".":
                dp[y][x] += q
                q += 1
            else:
                q = 0
            x -= 1
    for x in range(w):
        y = 0
        q = 0
        while 0 <= y < h:
            if s[y][x] == ".":
                dp[y][x] += q
                q += 1
            else:
                q = 0
            y += 1
        y = h - 1
        q = 0
        while 0 <= y < h:
            if s[y][x] == ".":
                dp[y][x] += q
                q += 1
            else:
                q = 0
            y -= 1
    print(max(map(lambda x: max(x), dp)))
    return


#Solve
if __name__ == '__main__':
    D()

Submission status: Accepted

Solution code:
import numpy as np

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

D = np.zeros((H, W), dtype=int)
U = np.zeros((H, W), dtype=int)
L = np.zeros((H, W), dtype=int)
R = np.zeros((H, W), dtype=int)

for h in range(H):
    U[h] = (U[h - 1] + 1) * S[h]
    D[-h - 1] = (D[-h] + 1) * S[-h - 1]
for w in range(W):
    L[:, w] = (L[:, w - 1] + 1) * S[:, w]
    R[:, -w - 1] = (R[:, -w] + 1) * S[:, -w - 1]
print(np.max(U + D + L + R) - 3)

Submission status: Accepted

Solution code:
h, w = map(int, input().split())
sL = [input() for _ in range(h)]
L = [[0 for _ in range(w)] for _ in range(h)]
R = [[0 for _ in range(w)] for _ in range(h)]
U = [[0 for _ in range(w)] for _ in range(h)]
D = [[0 for _ in range(w)] for _ in range(h)]
for i in range(h):  # 行
    for j in range(w):  # 列
        if sL[i][j] != "#":
            if j == 0:
                L[i][j] = 1
            else:
                L[i][j] = L[i][j-1] + 1
        else:
            L[i][j] = 0
for i in range(h):  # 行
    for j in range(w-1, -1, -1):  # 列
        if sL[i][j] != "#":
            if j == w-1:
                R[i][j] = 1
            else:
                R[i][j] = R[i][j+1] + 1
        else:
            R[i][j] = 0
for j in range(w):  # 列
    for i in range(h):  # 行
        if sL[i][j] != "#":
            if i == 0:
                U[i][j] = 1
            else:
                U[i][j] = U[i-1][j] + 1
        else:
            U[i][j] = 0
for j in range(w):  # 列
    for i in range(h-1, -1, -1):  # 行
        if sL[i][j] != "#":
            if i == h-1:
                D[i][j] = 1
            else:
                D[i][j] = D[i+1][j] + 1
        else:
            D[i][j] = 0
max_ = 0
sum_ = 0
for i in range(h):
    for j in range(w):
        sum_ = L[i][j] + R[i][j] + U[i][j] + D[i][j] - 3
        if sum_ > max_:
            max_ = sum_
print(max_)

Submission status: Accepted

Solution code:
h, w = map(int, input().split())
S = [input() for _ in range(h)]
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):
    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
    for j in reversed(range(w)):
        if S[i][j] == '.':
            if j == w-1:
                R[i][j] = 1
            else:
                R[i][j] = R[i][j+1] + 1
for j in range(w):
    for i in range(h):
        if S[i][j] == '.':
            if i == 0:
                U[i][j] = 1
            else:
                U[i][j] = U[i-1][j] + 1
    for i in reversed(range(h)):
        if S[i][j] == '.':
            if i == h-1:
                D[i][j] = 1
            else:
                D[i][j] = D[i+1][j] + 1
ans = 0
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)

Submission status: Accepted

Solution code:
h, w = map(int, input().split())
S = [list(input()) for _ in range(h)]
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):
    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
    for j in reversed(range(w)):
        if S[i][j] == '.':
            if j == w-1:
                R[i][j] = 1
            else:
                R[i][j] = R[i][j+1] + 1
for j in range(w):
    for i in range(h):
        if S[i][j] == '.':
            if i == 0:
                U[i][j] = 1
            else:
                U[i][j] = U[i-1][j] + 1
    for i in reversed(range(h)):
        if S[i][j] == '.':
            if i == h-1:
                D[i][j] = 1
            else:
                D[i][j] = D[i+1][j] + 1
ans = 0
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)