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:
from sys import stdin
def main():
  from builtins import range
  readline = stdin.readline
  h, w = map(int, readline().split())
  s = [readline().rstrip('\r\n') + '#' 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:
from sys import stdin
def main():
  from itertools import repeat
  from builtins import range
  readline = stdin.readline
  h, w = map(int, readline().split())
  s = [readline().rstrip('\r\n') + '#' for _ in range(h)]
  s.append('#' * w)
  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
          yokoi[start:j] = repeat(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:
from sys import stdin
def main():
  from builtins import range
  readline = stdin.readline
  h, w = map(int, readline().split())
  s = [readline().rstrip('\r\n') + '#' for _ in range(h)]
  s.append('#' * w)
  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
          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:
import numpy as np

H,W = map(int, input().split())
s = [list(input()) for j in range(H)]
s = (np.array(s) == ".") * 1

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


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

for j in reversed(range(W)):
    if j == W-1:
        R[:,j] = s[:,j]
    else:
        R[:,j] = (R[:,j+1] + 1) * s[:,j]


for i in range(H):
    if i == 0:
        U[i,:] = s[i,:]
    else:
        U[i,:] = (U[i-1,:] + 1) * s[i,:]

for i in reversed(range(H)):
    if i == H-1:
        D[i,:] = s[i,:]
    else:
        D[i,:] = (D[i+1,:] + 1) * s[i,:]

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

Submission status: Accepted

Solution code:
from sys import stdin
def main():
  from builtins import range
  readline = stdin.readline
  h, w = map(int, readline().split())
  s = [readline().rstrip('\r\n') + '#' for _ in range(h)]
  s.append('#' * w)
  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
          for k in range(start, j):
            yokoi[k] = 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:
def main():
    H, W = map(int, input().split())
    matrix = [list(input()) for _ in range(H)]
    count_matrix = [[0 for _ in range(W)] for _ in range(H)]

    # 横方向についてカウントする
    for i in range(H):
        start = 0
        count = 0
        for j in range(W):
            s = matrix[i][j]
            if s == '.':
                count += 1
                if j == W-1:
                    for k in range(start, j+1):
                        count_matrix[i][k] += count
            else:
                for k in range(start, j):
                    count_matrix[i][k] += count
                start = j+1
                count = 0

    # 縦方向についてカウントする
    for i in range(W):
        start = 0
        count = 0
        for j in range(H):
            s = matrix[j][i]
            if s == '.':
                count += 1
                if j == H-1:
                    for k in range(start, j+1):
                        count_matrix[k][i] += count
            else:
                for k in range(start, j):
                    count_matrix[k][i] += count
                start = j+1
                count = 0
    
    max_val = 0
    for i in range(H):
        for j in range(W):
            max_val = max(max_val, count_matrix[i][j])
    print(max_val-1)
    return

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def main():
    H, W = map(int, input().split())
    matrix = [list(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)]
    D = [[0 for _ in range(W)] for _ in range(H)]
    U = [[0 for _ in range(W)] for _ in range(H)]

    # 左方向についてカウントする
    for i in range(H):
        if matrix[i][0] == '.':
            L[i][0] = 1
        for j in range(1, W):
            s = matrix[i][j]
            if s == '.':
                L[i][j] = L[i][j-1] + 1

    # 右方向についてカウントする
    for i in range(H):
        if matrix[i][-1] == '.':
            R[i][-1] = 1
        for j in range(W-2, -1, -1):
            s = matrix[i][j]
            if s == '.':
                R[i][j] = R[i][j+1] + 1
    
    # 上方向についてカウントする
    for i in range(W):
        if matrix[0][i] == '.':
            U[0][i] = 1
        for j in range(1, H):
            s = matrix[j][i]
            if s == '.':
                U[j][i] = U[j-1][i] + 1
    
    # 下方向についてカウントする
    for i in range(W):
        if matrix[-1][i] == '.':
            D[-1][i] = 1
        for j in range(H-2, -1, -1):
            s = matrix[j][i]
            if s == '.':
                D[j][i] = D[j+1][i] + 1    
    
    max_val = -3
    for i in range(H):
        for j in range(W):
            max_val = max(max_val, R[i][j]+L[i][j]+U[i][j]+D[i][j])
    print(max_val-3)
    return

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from sys import stdin
def main():
  _readline, _range = stdin.readline, range
  h, w = map(int, _readline().split())
  s = [_readline().rstrip() + '#' for _ in _range(h)]
  s.append('#' * w)
  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
          for k in _range(start, j):
            yokoi[k] = 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:
def main():
    import sys
    #input = sys.stdin.readline
    H,W = map(int, input().split())
    S = [(input()) for i in range(H)]
    wall = "#"*W
    for i in range(H):
        S[i] += "#"
    S.append(wall)
    A = [([0]*W) for _ in range(H)]
    B = [([0]*W) for _ in range(H)]
    
    for i in range(H+1):
        for j in range(W):
            if i == 0:
                if S[i][j]  == ".":
                    A[i][j] = 1
            else:
                if S[i][j]  == ".":
                    A[i][j] = A[i-1][j] + 1
                else:
                    k = i-1
                    while k>=0 and A[k][j]>0:
                        A[k][j] = A[i-1][j]
                        k -= 1
    for j in range(W+1):
        for i in range(H):
            if j == 0:
                if S[i][j]  == ".":
                    B[i][j] = 1
            else:
                if S[i][j]  == ".":
                    B[i][j] = B[i][j-1] + 1
                else:
                    k = j-1
                    while k >=0 and B[i][k]>0:
                        B[i][k] = B[i][j-1]
                        k -= 1
    answer = 0
    for i in range(H):
        for j in range(W):
            tmp = A[i][j] + B[i][j] - 1
            if tmp >= answer:
                answer = tmp
    print(answer)
    
    
    
main()

Submission status: Accepted

Solution code:
from itertools import groupby
 
[H, W] = map(int, input().split())
Ss = [list(map( lambda x: int(x == "."), list(input()) )) for _ in range(H)]
 
res = 0
count = [[-Ss[i][j] for j in range(W)] for i in range(H)]
for i in range(H):
    j = 0
    for x in groupby(Ss[i]):
        k = len(list(x[1]))
        for _ in range(k):
            count[i][j] += k * x[0]
            j += 1

for j in range(W):
    i = 0
    for x in groupby([Ss[i][j] for i in range(H)]):
        k = len(list(x[1]))
        for _ in range(k):
            new_res = count[i][j] + k * x[0]
            if res < new_res:
                res = new_res
            i += 1

print(res)

Submission status: Accepted

Solution code:
import numpy as np
H, W = map(int, input().split())
A = []
for _ in range(H):
    vec = list(map(lambda x: 0 if x=='#' else 1, list(input())))
    A.append(vec)

A = np.array(A)
top = np.zeros((H+1, W), dtype=np.int)
bottom = np.zeros((H+1, W), dtype=np.int)
left = np.zeros((H, W+1), dtype=np.int)
right = np.zeros((H, W+1), dtype=np.int)

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

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

for i in range(1, W+1):
    left[:, i] = (left[:, i-1] + 1) * A[:, i-1]
    
for i in range(W-1, -1, -1):
    right[:, i] = (right[:, i+1] + 1) * A[:, i]
    
C = top[1:H+1, :] + bottom[0:H, :] - A
R = left[:, 1:W+1] + right[:, 0:W] - A
CR = C + R - A
print(CR.max())

Submission status: Accepted

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

yoko = [[0] * w for _ in range(h)]
for i in range(h):
  start = -1
  for j in range(w + 1):
    if s[i][j] == '#':
      if start != -1:
        for k in range(start, j):
          yoko[i][k] = j - start
        start = -1
    else:
      if start == -1:
        start = j

tate = [[0] * w for _ in range(h)]
for i in range(w):
  start = -1
  for j in range(h + 1):
    if s[j][i] == '#':
      if start != -1:
        for k in range(start, j):
          tate[k][i] = j - start
        start = -1
    else:
      if start == -1:
        start = j

result = 0
for i in range(h):
  for j in range(w):
    t = yoko[i][j] + tate[i][j] - 1
    if t > result:
      result = t

print(result)

Submission status: Accepted

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

yoko = [[0] * w for _ in range(h)]
for i in range(h):
  si = s[i]
  start = -1
  for j in range(w + 1):
    if si[j] == '#':
      if start != -1:
        for k in range(start, j):
          yoko[i][k] = j - start
        start = -1
    else:
      if start == -1:
        start = j

tate = [[0] * w for _ in range(h)]
for i in range(w):
  start = -1
  for j in range(h + 1):
    if s[j][i] == '#':
      if start != -1:
        for k in range(start, j):
          tate[k][i] = j - start
        start = -1
    else:
      if start == -1:
        start = j

result = 0
for i in range(h):
  yokoi = yoko[i]
  tatei = tate[i]
  for j in range(w):
    t = yokoi[j] + tatei[j] - 1
    if t > result:
      result = t

print(result)

Submission status: Accepted

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

yoko = [[0] * w for _ in range(h)]
for i in range(h):
  si = s[i]
  jj = -1
  for j in range(w):
    if si[j] == '.':
      start = j
      jj = j + 1
      break
  if jj == -1:
    continue
  for j in range(jj, w + 1):
    if si[j] == '#':
      if start != -1:
        for k in range(start, j):
          yoko[i][k] = j - start
        start = -1
    else:
      if start == -1:
        start = j

tate = [[0] * w for _ in range(h)]
for i in range(w):
  jj = -1
  for j in range(h):
    if s[j][i] == '.':
      start = j
      jj = j + 1
      break
  if jj == -1:
    continue
  for j in range(jj, h + 1):
    if s[j][i] == '#':
      if start != -1:
        for k in range(start, j):
          tate[k][i] = j - start
        start = -1
    else:
      if start == -1:
        start = j

result = 0
for i in range(h):
  yokoi = yoko[i]
  tatei = tate[i]
  for j in range(w):
    t = yokoi[j] + tatei[j] - 1
    if t > result:
      result = t

print(result)

Submission status: Accepted

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

yoko = [[0] * w for _ in range(h)]
for i in range(h):
  si = s[i]
  if si[0] == '.':
    start = 0
  else:
    start = -1
  for j in range(1, w + 1):
    if si[j] == '#':
      if start != -1:
        for k in range(start, j):
          yoko[i][k] = j - start
        start = -1
    else:
      if start == -1:
        start = j

tate = [[0] * w for _ in range(h)]
for i in range(w):
  if s[0][i] == '.':
    start = 0
  else:
    start = -1
  for j in range(1, h + 1):
    if s[j][i] == '#':
      if start != -1:
        for k in range(start, j):
          tate[k][i] = j - start
        start = -1
    else:
      if start == -1:
        start = j

result = 0
for i in range(h):
  yokoi = yoko[i]
  tatei = tate[i]
  for j in range(w):
    t = yokoi[j] + tatei[j] - 1
    if t > result:
      result = t

print(result)

Submission status: Accepted

Solution code:
import sys
stdin = sys.stdin
read_int = lambda : list(map(int,stdin.readline().split()))
H, W = read_int()

range_W = range(W)
range_H = range(H)
# nomal
# 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]
# res = [[0 for _ in range_W] for _ in range_H]

# Pypy
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]
res = [[0] * W for _ in range_H]
grid = []

append = grid.append
for i in range_H:
    row = list(" ".join(input()).split())
    append(row)

def solve():
    ans = 0
    for i in range_H:
        for j in range_W:
            if grid[i][j] == ".":
                L[i][j] = 1 if j == 0 else L[i][j - 1] + 1
                U[i][j] = 1 if i == 0 else U[i - 1][j] + 1
                res[i][j] += L[i][j] + U[i][j]
                ans = max(res[i][j], ans)

            if grid[H - i - 1][W - j - 1] == ".":
                R[H - i - 1][W - j - 1] = 1 if j == 0 else R[H - i - 1][W - j] + 1
                D[H - i - 1][W - j - 1] = 1 if i == 0 else D[H - i][W - j - 1] + 1
                res[H - i - 1][W - j - 1] += R[H - i - 1][W - j - 1] + D[H - i - 1][W - j - 1]
                ans = max(res[H - i - 1][W - j - 1], ans)
    return ans - 3

if __name__ == "__main__":
    print(solve())

Submission status: Accepted

Solution code:

#38 ABC129D
h,w=map(int,input().split())
s=[input() for _ in range(h)]

x=[[0 for _ in range(w)] for _ in range(h)]
y=[[0 for _ in range(w)] for _ in range(h)]

t=0
for i in range(h):
	t=0
	for j in range(w):
		if s[i][j]==".":
			t+=1
		else:
			t=0
		x[i][j]=t
for i in range(h):
	for j in range(1,w):
		if x[i][w-j-1]==0:
			continue
		elif x[i][w-j]==0:
			continue
		else:
			x[i][w-j-1]=x[i][w-j]

t=0
for j in range(w):
	t=0
	for i in range(h):
		if s[i][j]==".":
			t+=1
		else:
			t=0
		y[i][j]=t
for j in range(w):
	for i in range(1,h):
		if y[h-i-1][j]==0:
			continue
		elif y[h-i][j]==0:
			continue
		else:
			y[h-i-1][j]=y[h-i][j]

z=[[x[i][j]+y[i][j] for j in range(w)] for i in range(h)]
res=0
for t in z:
	res=max(res,max(t))
print(max(0,res-1))

Submission status: Accepted

Solution code:
import sys, math, heapq
stdin = sys.stdin
read_int = lambda : list(map(int,stdin.readline().split()))
H, W = read_int()


# nomal
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)]
res = [[0 for _ in range(W)] for _ in range(H)]
grid = []

for i in range(H):
    row = list(" ".join(input()).split())
    grid.append(row)

def solve():
    ans = 0
    for i in range(H):
        for j in range(W):
            if grid[i][j] == ".":
                L[i][j] = 1 if j == 0 else L[i][j - 1] + 1
                U[i][j] = 1 if i == 0 else U[i - 1][j] + 1
                res[i][j] += L[i][j] + U[i][j]
                ans = max(res[i][j], ans)
 
            if grid[H - i - 1][W - j - 1] == ".":
                R[H - i - 1][W - j - 1] = 1 if j == 0 else R[H - i - 1][W - j] + 1
                D[H - i - 1][W - j - 1] = 1 if i == 0 else D[H - i][W - j - 1] + 1
                res[H - i - 1][W - j - 1] += R[H - i - 1][W - j - 1] + D[H - i - 1][W - j - 1]
                ans = max(res[H - i - 1][W - j - 1], ans)
    return ans - 3

if __name__ == "__main__":
    print(solve())

Submission status: Accepted

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

l = np.zeros((H,W))
l[:,-1] = S[:,-1]
r = np.zeros((H,W))
r[:,0] = S[:,0]
u = np.zeros((H,W))
u[-1] = S[-1]
d = np.zeros((H,W))
d[0] = S[0]

for i in range(W-2,-1,-1):
  l[:,i] = (l[:,i+1]+1)*S[:,i]
for i in range(1,W):
  r[:,i] = (r[:,i-1]+1)*S[:,i]
for i in range(H-2,-1,-1):
  u[i] = (u[i+1]+1)*S[i]
for i in range(1,H):
  d[i] = (d[i-1]+1)*S[i]

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

Submission status: Accepted

Solution code:
# can't AC without numpy, Python array handling with for is SLOW
import numpy as np
H, W = map(int, input().split())
S = []
for _ in range(H):
    S.append(list(input()))
S = (np.array(S) == ".") * 1

# i行j列に置いたとき上下左右の方向それぞれに光の軌跡が何マス伸びるか(自マスを含む)
trailLeft = np.zeros((H, W), dtype=int)
trailRight = np.zeros((H, W), dtype=int)
trailUp = np.zeros((H, W), dtype=int)
trailDown = np.zeros((H, W), dtype=int)

for i in range(H):
    if i == 0:
        trailUp[i] = S[i]
        trailDown[H - i - 1] = S[H - i - 1] * 1
    else:
        trailUp[i] = (trailUp[i - 1] + 1) * S[i]
        trailDown[H - i - 1] = (trailDown[H - i] + 1) * S[H - i - 1]

for j in range(W):
    if j == 0:
        trailLeft[:, j] = S[:, j]
        trailRight[:, W - j - 1] = S[:, W - j - 1] * 1
    else:
        trailLeft[:, j] = (trailLeft[:, j - 1] + 1) * S[:, j]
        trailRight[:, W - j - 1] = (trailRight[:, W - j] + 1) * S[:, W - j - 1]

print(np.max(trailLeft + trailRight + trailUp + trailDown - 3))

Submission status: Accepted

Solution code:
import numpy as np

H, W = map(int, input().split())
mat = np.array([[0 if v == "#" else 1 for v in input()] for _ in range(H)])

l, r = np.zeros((H, W)), np.zeros((H, W))
for w in range(W):
    l[:, w] = (l[:, w-1] + 1) * mat[:, w]
    r[:, -w-1] = (r[:, -w] + 1) * mat[:, -w-1]

u, d = np.zeros((H, W)), np.zeros((H, W))
for h in range(H):
    u[h, :] = (u[h - 1, :] + 1) * mat[h, :]
    d[-h - 1, :] = (d[-h, :] + 1) * mat[-h - 1, :]

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

Submission status: Accepted

Solution code:
import numpy as np
h, w = map(int, input().split())
S = np.array([list(input()) for _ 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 j in range(w):
    L[:,j]=(L[:,j-1]+1)*S[:,j]
    R[:,-j-1]=(R[:,-j]+1)*S[:,-j-1]
print(np.max(U+D+R+L)-3)

Submission status: Accepted

Solution code:
h,w=map(int, input().split())
s=list(list(input()) for i in range(h))
ans=0
dpL=[[0]*(w) for i in range(h)]
dpR=[[0]*(w) for i in range(h)]
dpU=[[0]*(w) for i in range(h)]
dpD=[[0]*(w) for i in range(h)]
#四方向用意
for i in range(h):
    for j in range(w):
        
        if s[i][j]=='.':
            if j==0:
                dpL[i][j]=1
            else:
                dpL[i][j]=dpL[i][j-1]+1
        else:
            continue
            
for i in range(h):
    for j in range(w-1,-1,-1):
        if s[i][j]=='.':
            if j==w-1:
                dpR[i][j]=1
            else:
                dpR[i][j]=dpR[i][j+1]+1
        else:
            continue
            
for i in range(w):
    for j in range(h):
        if s[j][i]=='.':
            if j==0:
                dpU[j][i]=1
            else:
                dpU[j][i]=dpU[j-1][i]+1
        else:
            continue
            
for i in range(w):
    for j in range(h-1,-1,-1):
        if s[j][i]=='.':
            if j==h-1:
                dpD[j][i]=1
            else:
                dpD[j][i]=dpD[j+1][i]+1
        else:
            continue

for i in range(h):
    for j in range(w):
        x=dpU[i][j]+dpD[i][j]+dpR[i][j]+dpL[i][j]-3
        if x>ans:
            ans=x
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:

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

S = []

for i in range(H):

    s = input()
    S.append(list(s))

yoko = []

for i in range(H):

    num = 0
    now = []

    for j in range(W):

        if S[i][j] == ".":
            num += 1

        else:
            now += ([num] * num)
            num = 0
            now.append(0)

    now += [num] * num
    yoko.append(now)

#print (yoko)

tate = []

for j in range(W):

    num = 0
    now = []

    for i in range(H):

        if S[i][j] == ".":
            num += 1

        else:
            now += ([num]*num)
            num = 0
            now.append(0)

    now += [num] * num
    tate.append(now)

ans = 0

for i in range(H):

    for j in range(W):

        ans = max(ans , yoko[i][j] + tate[j][i] - 1)

print (ans)

Submission status: Accepted

Solution code:
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)]
top = [[0]*W for _ in range(H)]
bottom = [[0]*W for _ in range(H)]

for j in range(W):
    cnt = 0
    for i in range(H):
        if S[i][j] == '#':
            cnt = 0
        else:
            cnt += 1
            top[i][j] = cnt
            
for j in range(W):
    cnt = 0
    for i in reversed(range(H)):
        if S[i][j] == '#':
            cnt = 0
        else:
            cnt += 1
            bottom[i][j] = cnt
            
for i in range(H):
    cnt = 0
    for j in range(W):
        if S[i][j] == '#':
            cnt = 0
        else:
            cnt += 1
            left[i][j] = cnt
            
for i in range(H):
    cnt = 0
    for j in reversed(range(W)):
        if S[i][j] == '#':
            cnt = 0
        else:
            cnt += 1
            right[i][j] = cnt
                        
ans = 0
for i in range(H):
    for j in range(W):
        ans = max(ans,left[i][j]+right[i][j]+top[i][j]+bottom[i][j]-3)
        
print(ans)

Submission status: Accepted

Solution code:
import numpy as np


def main():
    h, w = list(map(int, input().split()))
    grid = []
    for _ in range(h):
        grid.append(list(input()))

    grid = np.array(grid) == '.'
    # print(grid)

    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(1, h):
        U[i] = (U[i - 1] + 1) * grid[i - 1]
        # print(U[i])
    # print(U)

    for i in reversed(range(h - 1)):
        D[i] = (D[i + 1] + 1) * grid[i + 1]

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

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

    score = ((U + D + L + R) * grid).max() + 1
    print(score)


main()

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)
R = np.zeros((H, W), dtype=int)
L = 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(D + U + R + L) - 3)