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:
# input()
# int(input())
# map(int, input().split())
# list(map(int, input().split()))
# list(map(int, list(input()))) # スペースがない数字リストを読み込み
import math
import fractions
import sys
import bisect
import heapq  # 優先度付きキュー(最小値取り出し)
import collections
from collections import Counter
from collections import deque
import pprint
import itertools

sr = lambda: input()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

"""nを素因数分解"""
"""2以上の整数n => [[素因数, 指数], ...]の2次元リスト"""


def factorization(n):
    arr = []
    temp = n
    if n == 1:
        return arr

    for i in range(2, int(-(-n ** 0.5 // 1)) + 1):
        if temp % i == 0:
            cnt = 0
            while temp % i == 0:
                cnt += 1
                temp //= i
            arr.append([i, cnt])

    if temp != 1:
        arr.append([temp, 1])

    if arr == []:
        arr.append([n, 1])

    return arr


# a^n
def power(a, n, mod):
    x = 1
    while n:
        if n & 1:
            x *= a % mod
        n >>= 1
        a *= a % mod
    return x % mod


# n*(n-1)*...*(l+1)*l
def kaijo(n, l, mod):
    if n == 0:
        return 1
    a = n
    tmp = n - 1
    while (tmp >= l):
        a = a * tmp % mod
        tmp -= 1
    return a


inf = 10 ** 18
mod = 10 ** 9 + 7

h,w = lr()
s = [input() for i in range(h)]
dicw = [[0 for j in range(w)] for i in range(h)]
dich = [[0 for j in range(w)] for i in range(h)]
# まずは横方向の情報を格納
for i in range(h):
    ind = 0
    now = 0
    while ind < w:
        now = 0
        while ind < w and s[i][ind] == '.':
            now+=1
            ind+=1
        for j in range(now):
            dicw[i][ind-1-j] = now
        ind+=1
for i in range(w):
    ind = 0
    now = 0
    while ind < h:
        now = 0
        while ind < h and s[ind][i] == '.':
            now+=1
            ind+=1
        for j in range(now):
            dich[ind-1-j][i] = now
        ind+=1

ans = 0
for i in range(h):
    for j in range(w):
        if s[i][j] == '.':
            ans = max(ans, dich[i][j]+dicw[i][j]-1)
print(ans)

Submission status: Accepted

Solution code:
def main():
    H, W = map(int, input().split())
    A = [list(input()) for i in range(H)]
    right = [[0] * W for _ in range(H)]
    left = [[0] * W for _ in range(H)]
    upper = [[0] * W for _ in range(H)]
    under = [[0] * W for _ in range(H)]

    num_max_loc = 0

    for i in range(H):
        tmp_num = 0
        for j in range(W):
            if A[i][j] == "#":
                tmp_num = 0
            else:
                tmp_num += 1
                left[i][j] = tmp_num

    for i in range(H):
        tmp_num = 0
        for j in range(W-1, -1, -1):
            if A[i][j] == "#":
                tmp_num = 0
            else:
                tmp_num += 1
                right[i][j] = tmp_num

    for i in range(W):
        tmp_num = 0
        for j in range(H):
            if A[j][i] == "#":
                tmp_num = 0
            else:
                tmp_num += 1
                upper[j][i] = tmp_num

    for i in range(W):
        tmp_num = 0
        for j in range(H-1, -1, -1):
            if A[j][i] == "#":
                tmp_num = 0
            else:
                tmp_num += 1
                under[j][i] = tmp_num

    for i in range(H):
        for j in range(W):
            tmp_sum = (
                left[i][j] + right[i][j] + upper[i][j] + under[i][j] - 3)
            num_max_loc = max(num_max_loc, tmp_sum)

    print(num_max_loc)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
H, W = map(int, input().split())
s = []
for i in range(H):
    s.append(input())
ans = 0
ls = [[0 for i in range(W)] for j in range(H)]
for i, x in enumerate(s):
    cur = 1
    for j, y in enumerate(x):
        if y == '.':
            ls[i][j] += cur
            cur += 1
        else:
            ls[i][j] = 0
            cur = 1
    cur = 1
    for j, y in enumerate(x[::-1]):
        if y == '.':
            ls[i][W-j-1] += cur
            cur += 1
        else:
            ls[i][W-j-1] = 0
            cur = 1
for i in range(W):
    cur = 1
    for j in range(H):
        if s[j][i] == '.':
            ls[j][i] += cur
            cur += 1
        else:
            ls[j][i] = 0
            cur = 1
    cur = 1
    for j in range(H):
        if s[H-j-1][i] == '.':
            ls[H-j-1][i] += cur
            cur += 1
        else:
            ls[H-j-1][i] = 0
            cur = 1
for x in ls:
    for y in x:
        ans = max(ans, y)
print(ans-3)

Submission status: Accepted

Solution code:
h, w = map(int, input().split())
s = []
for i in range(h):
    s.append(input())
ans = [[0 for j in range(w)] for i in range(h)]
for i in range(h):
    done = [False] * 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+l] == "#":
                break
            l += 1
        for k in range(j, j+l):
            ans[i][k] += l
            done[k] = True
for j in range(w):
    done = [False] * h
    for i in range(h):
        if s[i][j] == "#":
            continue
        if done[i]:
            continue
        l = 0
        while i+l < h:
            if s[i+l][j] == "#":
                break
            l += 1
        for k in range(i, i+l):
            ans[k][j] += l
            done[k] = True
res = 0
for i in range(h):
    res = max(max(ans[i]), res)
res -= 1
print(res)

Submission status: Accepted

Solution code:
h, w = map(int, input().split())
s = []
for _ in range(h):
    s.append(input())
lis_row = [[0 for j in range(w)] for i in range(h)]
lis_column = [[0 for j in range(w)] for i in range(h)]
for i in range(h):
    tmp = 0
    lis = []
    for j in range(w):
        if s[i][j] == "#":
            lis.append(0)
            tmp = 0
        else:
            tmp += 1
            lis.append(tmp)
    now = 0
    for j in range(w-1, -1, -1):
        if lis[j] != 0:
            now = max(lis[j], now)
            lis_row[i][j] = now
        else:
            now = 0

for j in range(w):
    tmp = 0
    lis = []
    for i in range(h):
        if s[i][j] == "#":
            lis.append(0)
            tmp = 0
        else:
            tmp += 1
            lis.append(tmp)
    now = 0
    for i in range(h-1, -1, -1):
        if lis[i] != 0:
            now = max(lis[i], now)
            lis_column[i][j] = now
        else:
            now = 0
ans = 0
for i in range(h):
    for j in range(w):
        if s[i][j] == ".":
            ans = max(ans, lis_row[i][j] + lis_column[i][j] -1)
print(ans)

Submission status: Accepted

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

for i in range(h):
    s[i] = input()

cnt_ver = [[0] * w for _ in range(h)]
cnt_hor = [[0] * w for _ in range(h)]

# check vertical
for i in range(w):
    for j in range(h):
        if s[j][i] == "#":
            cnt_ver[j][i] = 0
        elif j - 1 < 0 or s[j - 1][i] == "#":
            cnt_ver[j][i] = 1
        else:
            cnt_ver[j][i] = cnt_ver[j - 1][i] + 1

for i in range(w):
    for j in range(h - 1, -1, -1):
        if s[j][i] == "#":
            continue
        elif j + 1 < h and cnt_ver[j + 1][i] != 0:
            cnt_ver[j][i] = cnt_ver[j + 1][i]

# check horizontal
for i in range(h):
    for j in range(w):
        if s[i][j] == "#":
            cnt_hor[i][j] = 0
        elif j - 1 < 0 or s[i][j - 1] == "#":
            cnt_hor[i][j] = 1
        else:
            cnt_hor[i][j] = cnt_hor[i][j - 1] + 1

for i in range(h):
    for j in range(w - 1, -1, -1):
        if s[i][j] == "#":
            continue
        elif j + 1 < w and cnt_hor[i][j + 1] != 0:
            cnt_hor[i][j] = cnt_hor[i][j + 1]

ans = 0

for i in range(h):
    for j in range(w):
        ans = max(ans, cnt_hor[i][j] + cnt_ver[i][j] - 1)

print(ans)

Submission status: Accepted

Solution code:
#lamp
import sys
input=sys.stdin.readline
h,w=map(int,input().split())
lists=[]
for i in range(h):
    b=list(input())
    lists.append(b)
    
right=[[0 for i in range(w)] for j in range(h)]
left=[[0 for i in range(w)] for j in range(h)]
up=[[0 for i in range(w)] for j in range(h)]
down=[[0 for i in range(w)] for j in range(h)]

#rightの累積和
for i in range(h):
    for j in range(w-1,-1,-1):
        if j==w-1:
            if lists[i][j]=="#":
                right[i][j]=0
            else:
                right[i][j]=1
        else:
            if lists[i][j+1]=="#":
                if lists[i][j]=="#":
                    right[i][j]=0
                else:
                    right[i][j]=1
            elif lists[i][j+1]==".":
                if lists[i][j]=="#":
                    right[i][j]=0
                else:
                    right[i][j]=right[i][j+1]+1


#leftの累積和
for i in range(h):
    for j in range(w):
        if j==0:
            if lists[i][j]=="#":
                left[i][j]=0
            else:
                left[i][j]=1
        else:
            if lists[i][j]=="#":
                left[i][j]=0
            else:
                left[i][j]=left[i][j-1]+1


#upの累積和
for i in range(w):
    for j in range(h):
        if j==0:
            if lists[j][i]=="#":
                up[j][i]=0
            else:
                up[j][i]=1
        else:
            if lists[j][i]=="#":
                up[j][i]=0
            else:
                up[j][i]=up[j-1][i]+1

                
#downの累積和
for i in range(w):
    for j in range(h-1,-1,-1):
        if j==h-1:
            if lists[j][i]=="#":
                down[j][i]=0
            else:
                down[j][i]=1
        else:
            if lists[j][i]=="#":
                down[j][i]=0
            else:
                down[j][i]=down[j+1][i]+1
                
maxi=0
for i in range(h):
    for j in range(w):
        maxi=max(maxi,right[i][j]+left[i][j]+up[i][j]+down[i][j]-3)
print(maxi)

Submission status: Accepted

Solution code:
import numpy as np


H, W = map(int, input().split())
field = [[c == "." for c in input()] for _ in range(H)]
field = np.array(field, dtype=np.int16)

u = field.copy()
d = field.copy()
l = field.copy()
r = field.copy()

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

for j in range(1, W):
    l[:, j] = (l[:, j - 1] + 1) * l[:, j]
    r[:, -j - 1] = (r[:, -j] + 1) * r[:, -j - 1]

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

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)]
for i in range(h):
    for j in range(w):
        if j == 0 and S[i][j] != '#':
            L[i][j] = 1
        elif S[i][j] != '#':
            L[i][j] = L[i][j-1] + 1
R = [[0]*w for _ in range(h)]
for i in range(h):
    for j in range(w-1, -1, -1):
        if j == w-1 and S[i][j] != '#':
            R[i][j] = 1
        elif S[i][j] != '#':
            R[i][j] = R[i][j+1] + 1
U = [[0]*w for _ in range(h)]
for j in range(w):
    for i in range(h):
        if i == 0 and S[i][j] != '#':
            U[i][j] = 1
        elif S[i][j] != '#':
            U[i][j] = U[i-1][j] + 1
D = [[0]*w for _ in range(h)]
for j in range(w):
    for i in range(h-1, -1, -1):
        if i == h-1 and S[i][j] != '#':
            D[i][j] = 1
        elif S[i][j] != '#':
            D[i][j] = D[i+1][j] + 1
ans = -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)

Submission status: Accepted

Solution code:
import numpy as np
H ,W = map(int,input().split())

maze = [[] for _ in range(H)]
for i in range(H):
    maze[i] = np.array(list(input())) == "."
maze = np.array(maze)

up = np.zeros((H, W), dtype=int)
down = np.zeros((H, W), dtype=int)
right = np.zeros((H, W), dtype=int)
left = np.zeros((H, W), dtype=int)

for i in range(H):
    up[i] = (up[i-1] + 1)*maze[i]
    down[-(i+1)] = (down[-i] + 1)*maze[-(i+1)] 
    
#print(up)
#print(down)

for i in range(W):
    right[:, i] = (right[:, i-1] + 1)*maze[:, i]
    left[:, -(i+1)] = (left[:, -i] + 1)*maze[:, -(i+1)]

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

Submission status: Accepted

Solution code:

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

    count_h = [[0] * W for _ in range(H)]
    count_w = [[0] * W for _ in range(H)]

    tmp_cnt_h = [0] * W
    for i in range(H):
        w_cnt = 0
        for j,c in enumerate(S[i]):
            if c == '.':
                tmp_cnt_h[j] += 1
                w_cnt += 1
            else:
                count_w[i][j-w_cnt:j] = [w_cnt]*w_cnt
                w_cnt = 0

                h_cnt = tmp_cnt_h[j]
                for x in range(i-h_cnt,i):
                    count_h[x][j] = h_cnt
                tmp_cnt_h[j] = 0

        count_w[i][W-w_cnt:W] = [w_cnt]*w_cnt

    for i, h_cnt in enumerate(tmp_cnt_h):
        for x in range(H-h_cnt,H):
            count_h[x][i] = h_cnt

    max_light = 0
    for i in range(H):
        for j in range(W):
            max_light = max(max_light, count_h[i][j] + count_w[i][j])
    print(max_light-1)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys

read = sys.stdin.read
readline = sys.stdin.readline


def main():
    H, W = map(int, readline().split())
    S = read().split()

    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):
        c = 0
        for j in range(W):
            if S[i][j] == '#':
                c = 0
            else:
                L[i][j] = c
                c += 1
        c = 0
        for j in range(W - 1, -1, -1):
            if S[i][j] == '#':
                c = 0
            else:
                R[i][j] = c
                c += 1

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

    ans = 0
    for i in range(H):
        l, r, u, d = L[i], R[i], U[i], D[i]
        for j in range(W):
            if ans < l[j] + r[j] + u[j] + d[j] + 1:
                ans = l[j] + r[j] + u[j] + d[j] + 1

    print(ans)
    return


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60


def main():
    H, W = map(int, readline().split())
    S = [readline().strip() 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):
        c = 0
        for j in range(W):
            if S[i][j] == '#':
                c = 0
            else:
                L[i][j] = c
                c += 1
        c = 0
        for j in range(W - 1, -1, -1):
            if S[i][j] == '#':
                c = 0
            else:
                R[i][j] = c
                c += 1

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

    ans = 0
    for i in range(H):
        l, r, u, d = L[i], R[i], U[i], D[i]
        for j in range(W):
            if ans < l[j] + r[j] + u[j] + d[j] + 1:
                ans = l[j] + r[j] + u[j] + d[j] + 1

    print(ans)
    return


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60


def main():
    H, W = map(int, readline().split())
    S = [readline().strip() 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):
        c = 0
        for j in range(W):
            if S[i][j] == '#':
                c = 0
            else:
                L[i][j] = c
                c += 1
        c = 0
        for j in range(W - 1, -1, -1):
            if S[i][j] == '#':
                c = 0
            else:
                R[i][j] = c
                c += 1

    for j in range(W):
        c = 0
        for i in range(H):
            if S[i][j] == '#':
                c = 0
            else:
                U[i][j] = c
                c += 1
        c = 0
        for i in range(H - 1, -1, -1):
            if S[i][j] == '#':
                c = 0
            else:
                D[i][j] = c
                c += 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] + 1)

    print(ans)
    return


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60


def main():
    H, W = map(int, readline().split())
    S = [readline().strip() 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):
        c = 0
        for j in range(W):
            if S[i][j] == '#':
                c = 0
            else:
                L[i][j] = c
                c += 1
        c = 0
        for j in range(W - 1, -1, -1):
            if S[i][j] == '#':
                c = 0
            else:
                R[i][j] = c
                c += 1

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

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

    print(ans)
    return


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60


def main():
    H, W = map(int, readline().split())
    S = [readline().strip() 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):
        c = 0
        for j in range(W):
            if S[i][j] == '#':
                c = 0
            else:
                L[i][j] = c
                c += 1
        c = 0
        for j in range(W - 1, -1, -1):
            if S[i][j] == '#':
                c = 0
            else:
                R[i][j] = c
                c += 1

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

    ans = 0
    for i in range(H):
        for j in range(W):
            if S[i][j] == '.' and ans < L[i][j] + R[i][j] + U[i][j] + D[i][j] + 1:
                ans = L[i][j] + R[i][j] + U[i][j] + D[i][j] + 1

    print(ans)
    return


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
from itertools import groupby

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60


def len_count(S):
    H, W = len(S), len(S[0])
    L = [[0] * W for _ in range(H)]
    for row_S, row_L in zip(S, L):
        vec = [1]
        for i in range(1, W):
            if row_S[i - 1] == row_S[i]:
                vec[-1] += 1
            else:
                vec.append(1)

        idx = 0
        valid = row_S[0] == '.'
        for n in vec:
            if valid:
                for i in range(idx, idx + n):
                    row_L[i] = n
            idx += n
            valid = not valid

    return L


def main():
    H, W = map(int, readline().split())
    S = [readline().strip() for _ in range(H)]

    L1 = [[0] * W for _ in range(H)]
    for x in range(H):
        vec = [1]
        for i in range(1, W):
            if S[x][i - 1] == S[x][i]:
                vec[-1] += 1
            else:
                vec.append(1)

        idx = 0
        valid = S[x][0] == '.'
        for n in vec:
            if valid:
                for i in range(idx, idx + n):
                    L1[x][i] = n
            idx += n
            valid = not valid

    L2 = [[0] * W for _ in range(H)]
    for y in range(W):
        vec = [1]
        for i in range(1, H):
            if S[i - 1][y] == S[i][y]:
                vec[-1] += 1
            else:
                vec.append(1)

        idx = 0
        valid = S[0][y] == '.'
        for n in vec:
            if valid:
                for i in range(idx, idx + n):
                    L2[i][y] = n
            idx += n
            valid = not valid

    ans = 0
    for i in range(H):
        for j in range(W):
            if ans < L1[i][j] + L2[i][j] - 1:
                ans = L1[i][j] + L2[i][j] - 1

    print(ans)
    return


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
from itertools import groupby

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60


def len_count(S):
    H, W = len(S), len(S[0])
    L = [[0] * W for _ in range(H)]
    for row_S, row_L in zip(S, L):
        vec = [1]
        for i in range(1, W):
            if row_S[i - 1] == row_S[i]:
                vec[-1] += 1
            else:
                vec.append(1)

        idx = 0
        valid = row_S[0] == '.'
        for n in vec:
            if valid:
                for i in range(idx, idx + n):
                    row_L[i] = n
            idx += n
            valid = not valid

    return L


def main():
    H, W = map(int, readline().split())
    S = [readline().strip() for _ in range(H)]

    L1 = len_count(S)
    L2 = len_count(list(zip(*S)))

    ans = 0
    for i in range(H):
        for j in range(W):
            if ans < L1[i][j] + L2[j][i] - 1:
                ans = L1[i][j] + L2[j][i] - 1

    print(ans)
    return


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys

H, W = map(int, sys.stdin.readline().strip().split())
grid = []
for _ in range(H):
    grid.append(sys.stdin.readline().strip())

# (x, y)のx, y方向のscore [a, b]
scores_y = [[0 for _ in range(W)] for _ in range(H)]
scores_x = [[0 for _ in range(W)] for _ in range(H)]
for y in range(H):
    start = 0
    count = 0
    for x in range(W):
        if grid[y][x] == "#" or x == W-1:
            if x == W-1 and grid[y][x] != "#":
                count += 1
            for i in range(start, x+1):
                scores_x[y][i] = count
            count = 0
            start = x + 1
        else:
            count += 1

for x in range(W):
    start = 0
    count = 0
    for y in range(H):
        if grid[y][x] == "#" or y == H-1:
            if y == H-1 and grid[y][x] != "#":
                count += 1
            for i in range(start, y+1):
                scores_y[i][x] = count
            count = 0
            start = y + 1
        else:
            count += 1

# print(scores)
ans = 0
for y in range(H):
    for x in range(W):
        ans = max(ans, scores_x[y][x] + scores_y[y][x] - 1)
print(ans)

Submission status: Accepted

Solution code:
import numpy as np
h, w = map(int, input().split())
arr = np.array([list(input()) for _ in range(h)]) == "."
# print(arr)
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 i in range(h):
    u[i] = (u[i - 1] + 1) * arr[i] #arrがFalseだと0になる
    d[- i - 1] = (d[- i] + 1) * arr[- i - 1]

for j in range(w):
    l[:, j] = (l[:, j-1] + 1) * arr[:, j]
    r[:, - j - 1] = (r[:, - j] + 1) * arr[:, - j - 1]
# print(u)
print(np.max(u + d + l + r) - 3)

Submission status: Accepted

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

row_list = [[0] * w for _ in range(h)]
for i in range(h):
    r = 0
    cnt = 0
    for l in range(w):
        if s[i][l] == '#':
            row_list[i][l] = 0
            r += 1
            cnt = 0
            continue

        while r < w and s[i][r] == '.':
            cnt += 1
            r += 1

        row_list[i][l] = cnt

col_list = [[0] * h for _ in range(w)]
for i in range(w):
    r = 0
    cnt = 0
    for l in range(h):
        if s[l][i] == '#':
            col_list[i][l] = 0
            r += 1
            cnt = 0
            continue

        while r < h and s[r][i] == '.':
            cnt += 1
            r += 1

        col_list[i][l] = cnt

res = 0
for i in range(h):
    for j in range(w):
        res = max(res, row_list[i][j] + col_list[j][i] - 1)

print(res)

Submission status: Accepted

Solution code:
import numpy as np
def main():
    printl = lambda l: [print(x) for x in l]
    H, W = list(map(int, input().split()))
    A = np.array([[1 if i == '.' else 0 for i in input()] for _ in range(H)])
    L = np.zeros((H, W), dtype = np.int)
    R = np.zeros((H, W), dtype = np.int)
    U = np.zeros((H, W), dtype = np.int)
    D = np.zeros((H, W), dtype = np.int)
    L[:, 0] = A[:, 0]
    for w in range(1, W):
        L[:, w] = (L[:, w - 1] + 1) * A[:, w]
    R[:, W - 1] = A[:, W - 1]
    for w in range(W - 2, -1, -1):
        R[:, w] = (R[:, w + 1] + 1) * A[:, w]
    U[0, :] = A[0, :]
    for h in range(1, H):
        U[h, :] = (U[h - 1, :] + 1) * A[h, :]
    D[H - 1, :] = A[H - 1, :]
    for h in range(H - 2, -1, -1):
        D[h, :] = (D[h + 1, :] + 1) * A[h, :]
    print(np.max(L + R + U + D - 3))

if __name__ == '__main__':
    main()

Submission status: Accepted

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

for i in range(H):
  G.append(list(input()))
  
L=[[0]*W for i in range(H)]
R=[[0]*W for i in range(H)]
U=[[0]*W for i in range(H)]
D=[[0]*W for i in range(H)]

for i in range(H):
  for j in range(W):
    k=-i-1
    l=-j-1
    if G[i][j]=="#":
      L[i][j]=0
      U[i][j]=0
    else:
      if j==0:
        L[i][j]=1
        U[i][j]=U[i-1][j]+1
      elif i==0:
        L[i][j]=L[i][j-1]+1
        U[i][j]=1
      else:
        L[i][j]=L[i][j-1]+1
        U[i][j]=U[i-1][j]+1
        
    if G[k][l]=="#":
      R[k][l]=0
      D[k][l]=0
    else:
      if k==-1:
        R[k][l]=1
        D[k][l]=D[k+1][l]+1
      elif i==0:
        R[k][l]=R[k][l+1]+1
        D[k][l]=1
      else:
        R[k][l]=R[k][l+1]+1
        D[k][l]=D[k+1][l]+1
ans=0
for i in range(H):
  for j in range(W):
    #print(L[i][j],R[i][j],U[i][j],D[i][j])
    ans=max(R[i][j]+L[i][j]+U[i][j]+D[i][j]-3,ans)
print(ans)

Submission status: Accepted

Solution code:
def m():
    H, W = map(int, input().split())
    S = [list(input()) for _ in range(H)]
    Gx = [[-1 for _ in range(W)] for _ in range(H)]
    Gy = [[-1 for _ in range(W)] for _ in range(H)]

    for a in range(H):
        left = 0
        for b in range(W):
            if S[a][b] == '#':
                left = 0
            else:
                Gx[a][b] = left + 1
                left = Gx[a][b]
    for b in range(W):
        top = 0
        for a in range(H):
            if S[a][b] == '#':
                top = 0
            else:
                Gy[a][b] = top + 1
                top = Gy[a][b]

    for i in reversed(range(H)):
        right = 0
        for j in reversed(range(W)):
            if Gx[i][j] == -1:
                right = 0
            else:
                Gx[i][j] = max(Gx[i][j], right)
                right = Gx[i][j]

    for j in reversed(range(W)):
        bot = 0
        for i in reversed(range(H)):
            if Gy[i][j] == -1:
                bot = 0
            else:
                Gy[i][j] = max(Gy[i][j], bot)
                bot = Gy[i][j]
    ans = 0
    for i in range(H):
        for j in range(W):
            ans = max(Gx[i][j] + Gy[i][j], ans)
    return ans - 1


print(m())