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:
h, w = map(int,input().split())
s = [list(input()) for i in range(h)]

L = [[0] * w for i in range(h)]
R = [[0] * w for i in range(h)]
D = [[0] * w for i in range(h)]
U = [[0] * w for i in range(h)]
for i in range(h):
    for j in range(w):
        if j == 0:
            if s[i][j] == '.':
                L[i][j] = 1
            if s[i][- (j + 1)] =='.':
                R[i][- (j + 1)] = 1

        if j != 0:
            if s[i][j] == '.':
                L[i][j] = L[i][j - 1] + 1
            if s[i][- (j + 1)] == '.':
                R[i][- (j + 1)] = R[i][- (j + 1) + 1] + 1

        if i == 0:
            if s[i][j] == '.':
                U[i][j] = 1
            if s[- (i + 1)][j] == '.':
                D[- (i + 1)][j] = 1
        if i != 0:
            if s[i][j] == '.':
                U[i][j] = U[i - 1][j] + 1
            if s[- (i + 1)][j] == '.':
                D[- (i + 1)][j] = D[- (i + 1) + 1][j] + 1
ans = 0
for i in range(h):
    for j in range(w):
        if s[i][j] == '#':continue
        temp = R[i][j] + L[i][j] + D[i][j] + U[i][j] -3
        if ans < temp:ans = temp
        #print(temp)
print(ans)

Submission status: Accepted

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

map=[list(input()) for _ in range(h)]
map = [[1 if s == '.' else 0 for s in map[i]] for i in range(h)]

map = np.array(map,dtype=int)
l=map.copy()
r=map.copy()
u=map.copy()
d=map.copy()

for i in range(1,h):
    u[i] += u[i-1]
    u[i] *= map[i]
for i in range(h-1, 0, -1):
    d[i-1] += d[i]
    d[i-1] *= map[i-1]
for i in range(1,w):
    l[:, i] += l[:, i-1]
    l[:, i] *= map[:, i]
for i in range(w-1, 0, -1):
    r[:, i-1] += r[:, i]
    r[:, i-1] *= map[:, i-1]

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

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

from copy import deepcopy

h, w = map(int, readline().split())
s = [input() for _ in range(h)]
cnt_x = [[0] * w for _ in range(h)]
cnt_y = deepcopy(cnt_x)
for i in range(h):
    memo = 0
    for j in range(w):
        if s[i][j] == '.':
            memo += 1
            cnt_x[i][j] = memo
        else:
            memo = 0
    for j in range(w - 1, 0, -1):
        if s[i][j - 1] == '.':
            if cnt_x[i][j - 1] < cnt_x[i][j]:
                cnt_x[i][j - 1] = cnt_x[i][j]
for i in range(w):
    memo = 0
    for j in range(h):
        if s[j][i] == '.':
            memo += 1
            cnt_y[j][i] = memo
        else:
            memo = 0
    for j in range(h - 1, 0, -1):
        if s[j - 1][i] == '.':
            cnt_y[j - 1][i] = max(cnt_y[j - 1][i], cnt_y[j][i])
            if cnt_y[j - 1][i] < cnt_y[j][i]:
                cnt_y[j - 1][i] = cnt_y[j][i]
ans = 0
for i in range(h):
    for j in range(w):
        v = cnt_x[i][j] + cnt_y[i][j] - 1
        if ans < v:
            ans = v
print(ans)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
h, w = map(lambda x: int(x)+2, input().split())
MAZE = ['#'*w]
for _ in range(h-2):
    MAZE.append('#'+input()+'#')
else:
    MAZE.append('#'*w)

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

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

for i in range(1, h-1):
    for j in range(1, w-1):
        if MAZE[i][j] == '.':
            L[i][j+1] = L[i][j]+1
            U[i+1][j] = U[i][j]+1
        if MAZE[i][w-j] == '.':
            R[i][w-j-1] = R[i][w-j]+1
        if MAZE[h-i][j] == '.':
            D[h-i-1][j] = D[h-i][j]+1

ans = 0
for i in range(1, h-1):
    for j in range(1, w-1):
        if MAZE[i][j] == '#':
            continue
        LAMP[i][j] = L[i][j]+R[i][j]+U[i][j]+D[i][j]+1
        ans = max(ans, LAMP[i][j])

print(ans)

Submission status: Accepted

Solution code:
h,w=map(int,input().split())
s=[list(input()) for i in range(h)]
a=[[0]*w for j in range(h)]
b=[[0]*w for j in range(h)]
for i in range(h):
    k=0
    rep=0
    while k<w:
        cnt=0
        if s[i][k]==".":
            j=k
            while k<w and s[i][k]==".":
                k+=1
                cnt+=1
            for x in range(j,k):
                a[i][x]=cnt
        else:
            k+=1
for i in range(w):
    k=0
    while k<h:
        cnt=0
        if s[k][i]==".":
            j=k
            while k<h and s[k][i]==".":
                k+=1
                cnt+=1
            for x in range(j,k):
                b[x][i]=cnt
        else:
            k+=1
ans=0
for i in range(h):
    for j in range(w):
        ans=max(ans,a[i][j]+b[i][j])
print(ans-1)

Submission status: Accepted

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

lat = [[0] * w for _ in range(h)]
lng = [[0] * w for _ in range(h)]

for i in range(h):
    count = 0
    for j in range(w):
        if grid[i][j] == '#':
            for k in range(j-count, j):
                lat[i][k] = count
            count = 0
        else:
            count += 1
    for k in range(w-count, w):
        lat[i][k] = count

for j in range(w):
    count = 0
    for i in range(h):
        if grid[i][j] == '#':
            for k in range(i-count, i):
                lng[k][j] = count
            count = 0
        else:
            count += 1
    for k in range(h-count, h):
        lng[k][j] = count

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

print(ans)

Submission status: Accepted

Solution code:
H,W = map(int,input().split())
s = [[] for i in range(H)]
for i in range(H): s[i] = list(input())
l = [[0]*W for i in range(H)]
r = [[0]*W for i in range(H)]
d = [[0]*W for i in range(H)]
u = [[0]*W for i in range(H)]

for h in range(H):
    if s[h][0] == ".": l[h][0] = 1
    for w in range(1,W):
        if s[h][w] == ".": l[h][w] = l[h][w-1] + 1
    if s[h][W-1] == ".": r[h][W-1] = 1
    for w in range(1,W):
        if s[h][W-1-w] == ".": r[h][W-1-w] = r[h][W-w] + 1

for w in range(W):
    if s[0][w] == ".": d[0][w] = 1
    for h in range(1,H):
        if s[h][w] == ".": d[h][w] = d[h-1][w] + 1
    if s[H-1][w] == ".": u[H-1][w] = 1
    for h in range(1,H):
        if s[H-1-h][w] == ".": u[H-1-h][w] = u[H-h][w] + 1
ans = 0
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: Accepted

Solution code:
H, W = map(int, input().split())
S = []
for _ in range(H):
    S.append(input())
T = [[0] * (W + 1) for _ in range(H + 1)]
U = [[0] * (W + 1) for _ in range(H + 1)]


for y in range(H):
    for x in range(W):
        if S[y][x] == '.':
            if x == 0 or S[y][x - 1] == '#':
                start = x
            if x == W - 1 or S[y][x + 1] == '#':
                end = x
                long = end - start + 1
                T[y][start] += long
                T[y][end + 1] -= long
#print(T)
for y in range(H):
    for x in range(W):
        T[y][x + 1] += T[y][x]
#print(T)

for x in range(W):
    for y in range(H):
        if S[y][x] == '.':
            if y == 0 or S[y - 1][x] == '#':
                start = y
            if y == H - 1 or S[y + 1][x] == '#':
                end = y
                long = end - start + 1
                U[start][x] += long
                U[end + 1][x] -= long
#print(U)
for x in range(W):
    for y in range(H):
        U[y + 1][x] += U[y][x]
#print(U)

M = 0
for x in range(W):
    for y in range(H):
        M = max(M, T[y][x] + U[y][x] - 1)
print(M)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# coding: utf-8

import sys
import math
import collections
import itertools
from functools import lru_cache
INF = 10 ** 13
MOD = 10 ** 9 + 7
def input() : return sys.stdin.readline().strip()
def gcd(x, y) : return y if x % y == 0 else gcd(y, x % y)
def lcm(x, y) : return (x * y) // gcd(x, y)
def I() : return int(input())
def LI() : return [int(x) for x in input().split()]
def RI(N) : return [int(input()) for _ in range(N)]
def LRI(N) : return [[int(x) for x in input().split()] for _ in range(N)]
def LS() : return input().split()
def RS(N) : return [input() for _ in range(N)]
def LRS(N) : return [input().split() for _ in range(N)]
def PL(L) : print(*L, sep="\n")

H, W = LI()
S = RS(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):
    lf = 0
    rf = 0
    for j in range(W):
        if S[i][j] == ".":
            lf += 1
            L[i][j] = lf
        else:
            lf = 0

        if S[i][W-1-j] == ".":
            rf += 1
            R[i][W-1-j] = rf
        else:
            rf = 0

for i in range(W):
    uf = 0
    df = 0
    for j in range(H):
        if S[j][i] == ".":
            df += 1
            D[j][i] = df
        else:
            df = 0

        if S[H-1-j][i] == ".":
            uf += 1
            U[H-1-j][i] = uf
        else:
            uf = 0

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

print(ans)

Submission status: Accepted

Solution code:
H,W=map(int,input().split())
S=[list(input()) for i in range(H)]
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)]
res=0
for i in range(H):
    for j in range(W):
        if(S[i][j]=='#'):
            L[i][j]=0
        elif(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]=='#'):
            R[i][j]=0
        elif(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]=='#'):
            U[i][j]=0
        elif(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]=='#'):
            D[i][j]=0
        elif(i==H-1):
            D[i][j]=1
        else:
            D[i][j]=D[i+1][j]+1
for i in range(H):
    for j in range(W):
        res=max(res,U[i][j]+D[i][j]+L[i][j]+R[i][j]-3)
print(res)

Submission status: Accepted

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

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

H, W = lr()
S = [list(sr()) for _ in range(H)]
S = np.array([[1 if x == '.' else 0 for x in row] for row in S], np.bool)
up = np.zeros((H, W), np.int32)
down = np.zeros((H, W), np.int32)
right = np.zeros((H, W), np.int32)
left = np.zeros((H, W), np.int32)
for i in range(H-1):
    up[i+1] = (1+up[i]) * S[i]
for i in range(H-1, 0, -1):
    down[i-1] = (1+down[i]) * S[i]
for i in range(W-1):
    left[:, i+1] = (1+left[:, i]) * S[:, i]
for i in range(W-1, 0, -1):
    right[:, i-1] = (1+right[:, i]) * S[:, i]

answer = ((up + down + left + right) * S).max() + 1
print(answer)

Submission status: Accepted

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

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

H, W = lr()
S = [list(sr()) for _ in range(H)]
S = np.array([[1 if x == '.' else 0 for x in row] for row in S])
up = np.zeros((H, W), np.int32)
down = np.zeros((H, W), np.int32)
right = np.zeros((H, W), np.int32)
left = np.zeros((H, W), np.int32)
for i in range(H-1):
    up[i+1] = (1+up[i]) * S[i]
for i in range(H-1, 0, -1):
    down[i-1] = (1+down[i]) * S[i]
for i in range(W-1):
    left[:, i+1] = (1+left[:, i]) * S[:, i]
for i in range(W-1, 0, -1):
    right[:, i-1] = (1+right[:, i]) * S[:, i]

answer = ((up + down + left + right) * S).max() + 1
print(answer)

Submission status: Accepted

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

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

H, W = lr()
S = [list(sr()) for _ in range(H)]
S = np.array([[1 if x == '.' else 0 for x in row] for row in S])
up = np.ones((H, W), np.int32)
up *= S
down = np.ones((H, W), np.int32)
down *= S
right = np.ones((H, W), np.int32)
right *= S
left = np.ones((H, W), np.int32)
left *= S
for i in range(H-1):
    up[i+1] += up[i]
    up[i+1] *= S[i+1]
for i in range(H-1, 0, -1):
    down[i-1] += down[i]
    down[i-1] *= S[i-1]
for i in range(W-1):
    left[:, i+1] += left[:, i]
    left[:, i+1] *= S[:, i+1]
for i in range(W-1, 0, -1):
    right[:, i-1] += right[:, i]
    right[:, i-1] *= S[:, i-1]

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

Submission status: Accepted

Solution code:
#learnt about numpy from this code thank you nohtaray
#source: https://atcoder.jp/contests/abc129/submissions/5850116
import bisect
import os
from collections import Counter, deque
from fractions import gcd
from functools import lru_cache
from functools import reduce
import functools
import heapq
import itertools
import math
import numpy as np
import re
import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")

H, W = list(map(int, sys.stdin.readline().split()))

S = np.array([list(sys.stdin.readline().rstrip()) for _ in range(H)]) == '.'
ups = np.zeros((H, W), dtype=int)
downs = np.zeros((H, W), dtype=int)
rights = np.zeros((H, W), dtype=int)
lefts = np.zeros((H, W), dtype=int)

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

Submission status: Accepted

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

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

H, W = lr()
S = [list(sr()) for _ in range(H)]
up = np.array([[1 if x == '.' else 0 for x in row] for row in S])
down = up.copy()
right = up.copy()
left = up.copy()
S = up.copy()
for i in range(H-1):
    up[i+1] += up[i]
    up[i+1] *= S[i+1]
for i in range(H-1, 0, -1):
    down[i-1] += down[i]
    down[i-1] *= S[i-1]
for i in range(W-1):
    left[:, i+1] += left[:, i]
    left[:, i+1] *= S[:, i+1]
for i in range(W-1, 0, -1):
    right[:, i-1] += right[:, i]
    right[:, i-1] *= S[:, i-1]

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

Submission status: Accepted

Solution code:
h, w = map(int, input().split())
grid = [['#' for i in range(w+2)]]
for i in range(h):
  grid.append(['#'] + [s for s in str(input())] + ['#'])
grid.append(['#' for i in range(w+2)])

ud = [[0 for j in range(w+2)] for i in range(h+2)]
lr = [[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 grid[i][j] == '#': continue

    if ud[i-1][j] > 0:
      ud[i][j] = ud[i-1][j]
    else:
      cnt = 0
      d = i
      while grid[d][j] != '#':
        cnt += 1
        d += 1
      ud[i][j] = cnt

    if lr[i][j-1] > 0:
      lr[i][j] = lr[i][j-1]
    else:
      cnt = 0
      r = j
      while grid[i][r] != '#':
        cnt += 1
        r += 1
      lr[i][j] = cnt

ans = 0
for i in range(1, h+1):
  for j in range(1, w+1):
    if grid[i][j] == '#': continue
    cnt = ud[i][j] + lr[i][j] - 1
    ans = max(ans, cnt)
    #print(i, j, cnt)
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)])
S = np.where(S==".", 1, 0)

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

for i in range(H):
    D[-i-1] = (D[-i]+1)*S[-i-1]
    U[i] = (U[i-1]+1)*S[i]
    
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(L+R+D+U)-3)

Submission status: Accepted

Solution code:
import numpy as np


H, W = map(int, input().split())
S = np.ones((H, W), dtype=np.bool)
for i in range(H):
    S[i] = [s == "." for s in input()]

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

# up
up[0, :] = S[0, :]
for h in range(1, H):
    up[h, :] = up[h - 1, :] + 1
    up[h, :] *= S[h, :]

# down
down[H - 1, :] = S[H - 1, :]
for h in reversed(range(0, H - 1)):
    down[h, :] = down[h + 1, :] + 1
    down[h, :] *= S[h, :]

# left
left[:, 0] = S[:, 0]
for w in range(1, W):
    left[:, w] = left[:, w - 1] + 1
    left[:, w] *= S[:, w]

# right
right[:, W - 1] = S[:, W - 1]
for w in reversed(range(0, W - 1)):
    right[:, w] = right[:, w + 1] + 1
    right[:, w] *= S[:, w]

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

Submission status: Accepted

Solution code:
def resolve():
    h, w = map(int, input().split())
    s = [list(input()) for i in range(h)]
    L= [[0 for i in range(w)] for j in range(h)]
    M= [[0 for i in range(w)] for j in range(h)]
    bom=0
    a=[]
    ans=0
    for  i in range(h):
        for j in range(w):
            if s[i][j]==".":
                bom += 1
                a.append(j)
            else:
                for k in a:
                    L[i][k]=bom
                bom=0
                a=[]
        for k in a:
            L[i][k] = bom
        bom=0
        a=[]
    for j in range(w):
        for i in range(h):
            if s[i][j]==".":
                bom += 1
                a.append(i)
            else:
                for k in a:
                    M[k][j]=bom
                bom=0
                a=[]
        for k in a:
            M[k][j] = bom
        bom=0
        a=[]

    for i in range(h):
        for j in range(w):
            ans=max(ans,L[i][j]+M[i][j]-1)
    print(ans)
resolve()

Submission status: Accepted

Solution code:
h, w = map(int, input().split())
t = ["#"] * (w + 2)
s = [["#"] + list(input()) + ["#"] for _ in range(h)]
s.append(t)
s.insert(0, t)
dp_n = [[0] * (w + 2) for _ in range(h + 2)]
dp_s = [[0] * (w + 2) for _ in range(h + 2)]
dp_e = [[0] * (w + 2) for _ in range(h + 2)]
dp_w = [[0] * (w + 2) for _ in range(h + 2)]
for i in range(1, h + 1):
    for j in range(1, w + 1):
        if s[i][j] == ".":
            dp_n[i][j] += dp_n[i - 1][j] + 1
        if s[h + 1 - i][j] == ".":
            dp_s[h + 1 - i][j] += dp_s[h + 2 - i][j] + 1
for j in range(1, w + 1):
    for i in range(1, h + 1):
        if s[i][j] == ".":
            dp_w[i][j] += dp_w[i][j - 1] + 1
        if s[i][w + 1 - j] == ".":
            dp_e[i][w + 1 - j] += dp_e[i][w + 2 - j] + 1
ans = 0
for i in range(1, h + 1):
    for j in range(1, w + 1):
        c = dp_n[i][j] + dp_s[i][j] + dp_e[i][j] + dp_w[i][j] - 3
        if c > ans:
            ans = c
print(ans)

Submission status: Accepted

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

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):
        if field[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(w)[::-1]:
        if field[i][j] == "#":
            r[i][j] = 0
        
        elif 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 field[i][j] == "#":
            d[i][j] = 0
        
        elif i == 0:
            d[i][j] = 1
        
        else:
            d[i][j] = d[i-1][j] + 1
    
for j in range(w):
    for i in range(h)[::-1]:
        if field[i][j] == "#":
            u[i][j] = 0
        
        elif i == h-1:
            u[i][j] = 1
        
        else:
            u[i][j] = u[i+1][j] + 1
        
max_light = 0       
for i in range(h):
    for j in range(w):
        n_light = l[i][j] + r[i][j] + u[i][j] + d[i][j] - 3
        
        max_light = max(max_light,n_light)

print(max_light)

Submission status: Accepted

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

H, W = map(int, input().split())
S = [list(input()[:-1]) 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):
    if S[i][0]=='.':
        L[i][0] = 1

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

for i in range(H):
    if S[i][W-1]=='.':
        R[i][W-1] = 1

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

for i in range(W):
    if S[0][i]=='.':
        U[0][i] = 1

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

for i in range(W):
    if S[H-1][i]=='.':
        D[H-1][i] = 1

for i in range(H-2, -1, -1):
    for j in range(W):
        if S[i][j]=='.':
            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:
#どっちで出すか注意, rstrip注意
#提出前に見返すこと！
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby
    #from itertools import product
    from bisect import bisect_left,bisect_right
    import heapq
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    #mod = 10**9 + 7

    H,W = map(int, input().split())
    S = [list(input().rstrip()) for _ in range(H)]
    tate = [[0]*W for _ in range(H)]
    yoko = [[0]*W for _ in range(H)]

    for i in range(H):
        for j in range(W):
            if S[i][j] == '#':
                yoko[i][j] = 0
            else:
                if j==0:
                    yoko[i][j] = 1
                else:
                    yoko[i][j] = yoko[i][j-1] + 1
        for j in range(W-1, 0, -1):
            if yoko[i][j-1]==0 or yoko[i][j]==0:
                continue
            yoko[i][j-1] = yoko[i][j]
    
    for i in range(W):
        for j in range(H):
            if S[j][i] == '#':
                tate[j][i] = 0
            else:
                if j==0:
                    tate[j][i] = 1
                else:
                    tate[j][i] = tate[j-1][i] + 1
        for j in range(H-1, 0, -1):
            if tate[j-1][i]==0 or tate[j][i]==0:
                continue
            tate[j-1][i] = tate[j][i]
    res = 0
    for i in range(H):
        for j in range(W):
            res = max(res, tate[i][j]+yoko[i][j])
    print(res-1)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

h,w=map(int,input().split())
G=[]
for i in range(h):
    S=input()
    g=[]
    cnt=0
    for s in S:
        if s==".":
            cnt+=1
        else:
            if cnt==0:
                g.append(0)
            else:
                for j in range(cnt):
                    g.append(cnt)
                g.append(0)
                cnt=0
    if cnt>0:
        for j in range(cnt):
            g.append(cnt)
    G.append(g)

ans=0
for i in range(w):
    cnt=0 #壁じゃないマスの個数
    m=0 #最大値
    for j in range(h):
        g=G[j][i] #現在のマス(縦に見る)
        if g==0:
            if cnt!=0:
                ans=max(m+cnt-1,ans)
                cnt=0
                m=0
        else:
            cnt+=1
            m=max(g,m)
    if cnt>0:
        ans=max(m+cnt-1,ans)

print(ans)

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 h in range(H):
    for w in range(W):
        if S[h][w] == "#":
            L[h][w] = 0
        elif w == 0:
            L[h][w] = 1
        else:
            L[h][w] = L[h][w-1]+1

        if S[h][W-w-1] == "#":
            R[h][W-w-1] = 0
        elif W-w-1 == W-1:
            R[h][W-w-1] = 1
        else:
            R[h][W-w-1] = R[h][W-w]+1

        if S[h][w] == "#":
            U[h][w] = 0
        elif h == 0:
            U[h][w] = 1
        else:
            U[h][w] = U[h-1][w]+1

        if S[H-h-1][w] == "#":
            D[H-h-1][w] = 0
        elif H-h-1 == H-1:
            D[H-h-1][w] = 1
        else:
            D[H-h-1][w] = D[H-h][w]+1

light_num = [[0]*W for _ in range(H)]
for h in range(H):
    for w in range(W):
        light_num[h][w] = L[h][w]+R[h][w]+U[h][w]+D[h][w]

print(max([max(l) for l in light_num])-3)

Submission status: Accepted

Solution code:
h,w = map(int,input().split())
list1 = []
list2 = []
 
for i in range(w):
  list2.append([])
 
for i in range(h):
  s = input()
  list1.append(s)
  for j in range(w):
    list2[j].append(s[j])
 
list3 = []
for i in range(h):
  list3.append([])
  
list4 = []
for i in range(w):
  list4.append([])
 
for i in range(h):
  tmp_list = list1[i].split('#')
  for tmp in tmp_list:
    leng = len(tmp)
    list3[i].extend([leng]*leng)
    list3[i].append(0)
    
for i in range(w):
  tmp_list = (''.join(list2[i])).split('#')
  for tmp in tmp_list:
    leng = len(tmp)
    list4[i].extend([leng]*leng)
    list4[i].append(0)
    
max_num = -1
for i in range(w):
  for j in range(h):
    list3[j][i] += list4[i][j]-1
    max_num = max(max_num, list3[j][i])
    
print(max_num)

Submission status: Accepted

Solution code:
h, w = map(int,input().split())
s = []
for i in range(h):
  s += [input()]
sh = [[0 for _ in range(h)] for _ in range(w)]
sw = [[0 for _ in range(w)] for _ in range(h)]
for i in range(h):
  c = 0
  for j in range(w):
    if s[i][j]=='.':
      c += 1
    else:
      sw[i][(j-c):j] = [c]*c
      c = 0
  if c>0:
    sw[i][(w-c):w] = [c]*c
for j in range(w):
  c = 0
  for i in range(h):
    if s[i][j]=='.':
      c += 1
    else:
      sh[j][(i-c):i] = [c]*c
      c = 0
  if c>0:
    sh[j][(h-c):h] = [c]*c
print(max([sw[i][j]+sh[j][i] for i in range(h) for j in range(w)])-1)

Submission status: Accepted

Solution code:
#abc129d
import numpy as np
h,w=map(int,input().split())
s=np.array([list(input()) for i in range(h)])=='.'
u=np.zeros((h,w),dtype=int)
d=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[-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(u+d+l+r-3))

Submission status: Accepted

Solution code:
import numpy
H,W = map(int,input().split())
S = numpy.array([[1 if i == '.' else 0 for i in input().strip()] for _ in range(H)])
S = numpy.array([S, S])

for w in range(1, W):
    S[0, :, w] += S[0, :, w] * S[0, :, w - 1]
for w in range(W - 2, -1, -1):
    S[0, :, w] = (S[0, :, w] != 0) * numpy.maximum(S[0, :, w], S[0, :, w + 1])
for h in range(1, H):
    S[1, h] += S[1, h] * S[1, h - 1]
for h in range(H - 2, -1, -1):
    S[1, h] = (S[1, h] != 0) * numpy.maximum(S[1, h], S[1, h + 1])

S = S[0]+S[1]
print(numpy.max(S)-1)

Submission status: Accepted

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

left=np.zeros((H, W))
right=np.zeros((H, W))
top=np.zeros((H, W))
bottom=np.zeros((H, W))

for i in range(W):
  if i==0:
    left[:,i]=S[:,i]
    right[:,-i-1]=S[:,-i-1]
  else:
    left[:,i]=(left[:,i-1]+1)*S[:,i]
    right[:,-i-1]=(right[:,-i]+1)*S[:,-i-1]
    
for i in range(H):
  if i==0:
    top[i,:]=S[i,:]
    bottom[-1-i,:]=S[-i-1,:]
  else:
    top[i,:]=(top[i-1,:]+1)*S[i,:]
    bottom[-1-i,:]=(bottom[-i,:]+1)*S[-i-1,:]
    
ans=left+top+right+bottom-3
    

print(int(ans.max()))