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

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

# 横
for i in range(H):
    done = [0] * W
    for j in range(W):
        if done[j]:
            continue
        if maze[i][j] == "#":
            continue
        l = 0
        while j + l < W:
            if maze[i][j+l] == "#":
                break
            l += 1
        for k in range(j,j+l):
            done[k] = 1
            cnt[i][k] += l





# 縦
for i in range(W):
    done = [0] * H
    for j in range(H):
        if done[j]:
            continue
        if maze[j][i] == "#":
            continue
        l = 0
        while j + l < H:
            if maze[j+l][i] == "#":
                break
            l += 1
        for k in range(j,j+l):
            done[k] = 1
            cnt[k][i] += l

ans = 0
for i in range(H):
    for j in range(W):
        ans = max(ans, cnt[i][j]-1)
print(ans)

Submission status: Accepted

Solution code:
import numpy as np
H, W = map(int, input().split())
S = np.zeros((H,W))
for i in range(H):
    Si = np.array([int(s == '.') for s in input()])
    S[i] = Si
    
top = S.copy()
bottom = S.copy()
left = S.copy()
right = S.copy()

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

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

print(np.max((top + bottom + left + right - 3).astype(np.int)))

Submission status: Accepted

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

cnt_l, cnt_r, cnt_u, cnt_d = [[0] * w for _ in range(h)], [[0] * w for _ in range(h)], [[0] * w for _ in range(h)], [[0] * w for _ in range(h)]

for i in range(h):
    for j in range(w):
        if data[i][j] == "#":
            cnt_l[i][j] = 0
        else:
            cnt_l[i][j] = cnt_l[i][j - 1] + 1
    
        if data[i][w - j - 1] == "#":
            cnt_r[i][w - j - 1] = 0
        else:
            if j == 0:
                cnt_r[i][w - j - 1] = 1
            else:
                cnt_r[i][w - j - 1] = cnt_r[i][w - j] + 1

for j in range(w):
    for i in range(h):
        if data[i][j] == "#":
            cnt_u[i][j] = 0
        else:
            cnt_u[i][j] = cnt_u[i - 1][j] + 1

        if data[h - i - 1][j] == "#":
            cnt_d[h - i - 1][j] = 0
        else:
            if i == 0:
                cnt_d[h - i - 1][j] = 1
            else:
                cnt_d[h - i - 1][j] = cnt_d[h - i][j] + 1

ans = 0
for i in range(h):
    for j in range(w):
        total= cnt_l[i][j] + cnt_r[i][j] + cnt_u[i][j] + cnt_d[i][j] - 3
        ans = max(ans, total)

print(ans)

Submission status: Accepted

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

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

R = [[0]*W for _ in range(H)]
D = [[0]*W for _ in range(H)]
for h in range(H-1, -1, -1):
    for w in range(W-1, -1, -1):
        if S[h][w] == "#":
            R[h][w] = 0
        elif w == W-1:
            R[h][w] = 1
        else:
            R[h][w] = R[h][w+1] + 1

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

dpl = [[1] * w for _ in range(h)]
dpr = [[1] * w for _ in range(h)]
dpu = [[1] * w for _ in range(h)]
dpd = [[1] * w for _ in range(h)]

for i, si in enumerate(s):
    for j, sij in enumerate(si):
        if sij == '#':
            dpl[i][j], dpu[i][j] = 0, 0
        elif sij == '.':
            if j - 1 >= 0:
                dpl[i][j] = dpl[i][j - 1] + 1
            if i - 1 >= 0:
                dpu[i][j] = dpu[i - 1][j] + 1
for i, si in enumerate(s[::-1]):
    i = h - i - 1
    for j, sij in enumerate(si[::-1]):
        j = w - j - 1
        if sij == '#':
            dpr[i][j], dpd[i][j] = 0, 0
        elif sij == '.':
            if j + 1 < w:
                dpr[i][j] = dpr[i][j + 1] + 1
            if i + 1 < h:
                dpd[i][j] = dpd[i + 1][j] + 1

ans = 0
for i in range(h):
    for j in range(w):
        cnt = dpl[i][j] + dpr[i][j] + dpu[i][j] + dpd[i][j]
        ans = max(ans, cnt)
print(ans - 3)

Submission status: Accepted

Solution code:

H, W = map(int, input().split())
X = [input() for _ in range(H)]

grid0 = [[0] * (W + 1) for _ in range(H + 1)]
for i in range(H):
    for j in range(W):
        grid0[i + 1][j + 1] = int(X[i][j] == ".")

# Left to right
for i in range(H + 1):
    for j in range(W):
        if grid0[i][j + 1] > 0:
            grid0[i][j + 1] += grid0[i][j]

# Right to left
for i in range(H + 1):
    for j in reversed(range(W)):
        if grid0[i][j] > 0:
            grid0[i][j] = max(grid0[i][j], grid0[i][j + 1])

grid1 = [[0] * (W + 1) for _ in range(H + 1)]
for i in range(H):
    for j in range(W):
        grid1[i + 1][j + 1] = int(X[i][j] == ".")

# Top to down
for i in range(H):
    for j in range(W + 1):
        if grid1[i + 1][j] > 0:
            grid1[i + 1][j] += grid1[i][j]

# Down to top
for i in reversed(range(H)):
    for j in range(W + 1):
        if grid1[i][j] > 0:
            grid1[i][j] = max(grid1[i][j], grid1[i + 1][j])

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

print(ans)

Submission status: Accepted

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

res=[[] for i in range(H)]
for i in range(H):
  count=0
  for j in range(W):
    if S[i][j]=='#':
      if j != 0 and S[i][j-1]=='.':
        res[i].append(count)
      res[i].append(0)
      count=0
      continue
    else:
      count += 1
      if j == W-1:
        res[i].append(count)

cum = [[] for i in range(len(res))]
for i in range(len(res)):
  for j in range(len(res[i])):
    if res[i][j]==0:cum[i].append(0)
    else:cum[i].extend([res[i][j]]*res[i][j])

res=[[] for i in range(W)]
for i in range(W):
  count=0
  for j in range(H):
    if S[j][i]=='#':
      if j != 0 and S[j-1][i]=='.':
        res[i].append(count)
      res[i].append(0)
      count=0
      continue
    else:
      count += 1
      if j == H-1:
        res[i].append(count)

cum2 = [[] for i in range(len(res))]
for i in range(len(res)):
  for j in range(len(res[i])):
    if res[i][j]==0:cum2[i].append(0)
    else:cum2[i].extend([res[i][j]]*res[i][j])

ans=0
for i in range(H):
  for j in range(W):
    tmp = cum[i][j]+cum2[j][i]-1
    if tmp > ans:ans=tmp

print(ans)

Submission status: Accepted

Solution code:
h,w=map(int,input().split())
s=[input() for _ in range(h)]
d1=[[0]*(w+1) for _ in range(h+1)]
d2=[[0]*(w+1) for _ in range(h+1)]
for i in range(h):
  k=1
  for j in range(w):
    if s[i][j]=='.':d1[i+1][k]+=1
    else:k=j+2
  for j in range(w):
    if s[i][j]=='.':d1[i+1][j+1]+=d1[i+1][j]
for j in range(w):
  k=1
  for i in range(h):
    if s[i][j]=='.':d2[k][j+1]+=1
    else:k=i+2
  for i in range(h):
    if s[i][j]=='.':d2[i+1][j+1]+=d2[i][j+1]
ans=0
for i in range(1,h+1):
  for j in range(1,w+1):
    d1[i][j]+=d2[i][j]-1
  ans=max(ans,max(d1[i]))
print(ans)

Submission status: Accepted

Solution code:
h, w = map(int, input().split())
w += 2
h += 2
grid = ["#" * w]

dpx = [[0] * w for _ in range(h)]
dpy = [[0] * w for _ in range(h)]
for y in range(1, h - 1):
    grid.append("#" + input() + "#")
    for x in range(1, w):
        if grid[y][x] == '.':
            dpx[y][x] = dpx[y][x - 1] + 1
            dpy[y][x] = dpy[y - 1][x] + 1
    for x in range(w - 2, 0, -1):
        if dpx[y][x] != 0 and dpx[y][x + 1] != 0:
            dpx[y][x] = dpx[y][x + 1]

max_val = 0
for y in range(h - 2, 0, -1):
    for x in range(1, w - 1):
        if dpy[y][x] != 0 and dpy[y + 1][x] != 0:
            dpy[y][x] = dpy[y + 1][x]
        val = dpy[y][x] + dpx[y][x] - 1
        if max_val < val:
            max_val = val
print(max_val)

Submission status: Accepted

Solution code:
def main():
    import sys
    input=sys.stdin.readline
    H,W=map(int,input().split())
    maze=[]
    for _ in range(H):
        s=input().rstrip()
        maze.append(s)
    lamp=[[0]*W for _ in range(H)]
    for i in range(H):
        num=0
        for j in range(W):
            if maze[i][j]=="#":
                for k in range(1,num+1):
                    lamp[i][j-k]=num
                num=0
            else:
                num+=1
                if j==W-1:
                    for k in range(num):
                        lamp[i][j-k]=num
    for i in range(W):
        num=0
        for j in range(H):
            if maze[j][i]=="#":
                for k in range(1,num+1):
                    lamp[j-k][i]+=num
                num=0
            else:
                num+=1
                if j==H-1:
                    for k in range(num):
                        lamp[j-k][i]+=num
    lamp=[i for j in lamp for i in j]
    print(max(lamp)-1)
    
if __name__=="__main__":
    main()

Submission status: Accepted

Solution code:
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()
def rand_N(ran1, ran2):
    return random.randint(ran1, ran2)
def rand_List(ran1, ran2, rantime):
    return [random.randint(ran1, ran2) for i in range(rantime)]
def rand_ints_nodup(ran1, ran2, rantime):
  ns = []
  while len(ns) < rantime:
    n = random.randint(ran1, ran2)
    if not n in ns:
      ns.append(n)
  return sorted(ns)

def rand_query(ran1, ran2, rantime):
  r_query = []
  while len(r_query) < rantime:
    n_q = rand_ints_nodup(ran1, ran2, 2)
    if not n_q in r_query:
      r_query.append(n_q)
  return sorted(r_query)

from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
import heapq
import math
from fractions import gcd
import random
import string
import copy
from itertools import combinations, permutations, product
from operator import mul
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7

#############
# Main Code #
#############

H, W = getNM()
S = [input() for i in range(H)]
score_w = [[0] * W for i in range(H)]
score_h = [[0] * W for i in range(H)]

for i in range(H):
    now = -1
    for j in range(W):
        if now == -1:
            # 初期化
            if S[i][j] == '.':
                now = 1
                score_w[i][j] = now
        else:
            # 次が.の時
            if S[i][j] == '.':
                now += 1
                score_w[i][j] = now
            # 次が#の時
            else:
                now = -1

    for j in range(1, W):
        if score_w[i][-j - 1] > 0:
            score_w[i][-j - 1] = max(score_w[i][-j - 1], score_w[i][-j])

for j in range(W):
    now = -1
    for i in range(H):
        if now == -1:
            # 初期化
            if S[i][j] == '.':
                now = 1
                score_h[i][j] = now
        else:
            # 次が.の時
            if S[i][j] == '.':
                now += 1
                score_h[i][j] = now
            # 次が#の時
            else:
                now = -1

    for i in range(1, H):
        if score_h[-i - 1][j] > 0:
            score_h[-i - 1][j] = max(score_h[-i - 1][j], score_h[-i][j])

ans = 0
for i in range(H):
    for j in range(W):
        if S[i][j] == ".":
            ans = max(ans, score_w[i][j] + score_h[i][j] - 1)
print(ans)

Submission status: Accepted

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

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

for i in range(H):
    done = [0]*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(l):
            cnt[i][j+k] += l
            done[j+k] = 1

for j in range(W):
    done = [0]*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(l):
            cnt[i+k][j] += l
            done[i+k] = 1

ans = 0

for i in range(H):
    for j in range(W):
        ans = max(ans, cnt[i][j]-1)

print(ans)

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


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

    cnt_w = [[0] * W for _ in range(H)]
    for h in range(H):
        cnt = 0
        for w in range(W):
            if grid[h][w] == "#":
                cnt = 0
            else:
                cnt += 1
            cnt_w[h][w] = cnt

    for h in range(H):
        cnt = 0
        for w in reversed(range(W)):
            if grid[h][w] == "#":
                cnt = 0
            else:
                cnt = max(cnt, cnt_w[h][w])
            cnt_w[h][w] = cnt

    cnt_h = [[0] * W for _ in range(H)]
    for w in range(W):
        cnt = 0
        for h in range(H):
            if grid[h][w] == "#":
                cnt = 0
            else:
                cnt += 1
            cnt_h[h][w] = cnt

    for w in range(W):
        cnt = 0
        for h in reversed(range(H)):
            if grid[h][w] == "#":
                cnt = 0
            else:
                cnt = max(cnt, cnt_h[h][w])
            cnt_h[h][w] = cnt

    res = 0
    for h in range(H):
        for w in range(W):
            res = max(res, cnt_w[h][w] + cnt_h[h][w] - 1)
    print(res)


if __name__ == '__main__':
    resolve()

Submission status: Accepted

Solution code:
import sys
import bisect


def input():
    return sys.stdin.readline().rstrip()


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

    # read and horizontal
    for i in range(H):
        s = list(input())
        S[i] = s
        con = 0
        for j in range(W):
            if s[j] == "#":
                con = 0
                continue
            elif con == 0:
                con = 1
                k = j + 1
                while k < W:
                    if s[k] == ".":
                        con += 1
                        k += 1
                    else:
                        break
                count[i][j] = con
            elif con > 0:
                count[i][j] = con

    pass
    # vertical
    for j in range(W):
        ##############
        con = 0
        for i in range(H):
            if S[i][j] == "#":
                con = 0
                continue
            elif con == 0:
                con = 1
                k = i + 1
                while k < H:
                    if S[k][j] == ".":
                        con += 1
                        k += 1
                    else:
                        break
                count[i][j] += con
            elif con > 0:
                count[i][j] += con

    m = 0
    for i in range(H):
        m =max(m,max(count[i]))
    print(m-1)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys, math
from collections import defaultdict, deque, Counter
from bisect import bisect_left, bisect_right
from itertools import combinations, permutations, product
from heapq import heappush, heappop
from functools import lru_cache
input = sys.stdin.readline
rs = lambda: input().strip()
ri = lambda: int(input())
rl = lambda: list(map(int, input().split()))
mod = 1000000007
sys.setrecursionlimit(1000000)

H, W = rl()
S = []
for i in range(H):
  s = rs()
  S.append(s + '#')
S.append('#'*(W+1))

tab = [[0 for _ in range(W+1)] for _ in range(H+1)]

for i in range(H):
  k = 0
  prev = -1
  for j in range(W+1):
    if S[i][j] == '#':
      n = j-prev-1
      while k < j:
        tab[i][k] += n
        k += 1
      tab[i][k] = 0
      k += 1
      prev = j

for j in range(W):
  k = 0
  prev = -1
  for i in range(H+1):
    if S[i][j] == '#':
      n = i-prev-1
      while k < i:
        tab[k][j] += n - 1
        k += 1
      tab[k][j] = 0
      k += 1
      prev = i

ans = 0
for i in range(H):
  for j in range(W):
    ans = max(ans, tab[i][j])
print(ans)

Submission status: Accepted

Solution code:
import sys, math
from collections import defaultdict, deque, Counter
from bisect import bisect_left, bisect_right
from itertools import combinations, permutations, product
from heapq import heappush, heappop
from functools import lru_cache
input = sys.stdin.readline
rs = lambda: input().strip()
ri = lambda: int(input())
rl = lambda: list(map(int, input().split()))
mod = 1000000007
sys.setrecursionlimit(1000000)

H, W = rl()
S = []
for i in range(H):
  s = rs()
  S.append(s + '#')
S.append('#'*(W+1))

tab = [[0 for _ in range(W+1)] for _ in range(H+1)]

for i in range(H):
  k = 0
  prev = -1
  for j in range(W+1):
    if S[i][j] == '#':
      n = j-prev-1
      while k < j:
        tab[i][k] += n
        k += 1
      tab[i][k] = 0
      k += 1
      prev = j

for j in range(W):
  k = 0
  prev = -1
  for i in range(H+1):
    if S[i][j] == '#':
      n = i-prev-1
      while k < i:
        tab[k][j] += n - int(tab[k][j]>0)
        k += 1
      tab[k][j] = 0
      k += 1
      prev = i

ans = 0
for i in range(H):
  for j in range(W):
    ans = max(ans, tab[i][j])
print(ans)

Submission status: Accepted

Solution code:
from collections import deque

H,W = map(int, input().split())
Ss = [str(input()) for _ in range(H)]

yoko = [[0 for _ in range(W)] for _ in range(H)]
tate = [[0 for _ in range(W)] for _ in range(H)]

for i in range(H):
    for j in range(W):
        if Ss[i][j] == "#" or yoko[i][j] != 0:
            continue
        else:
            paths = [[i,j]]
            temp = 1
            for k in range(j+1, W):
                if Ss[i][k] == ".":
                    temp+=1
                    paths.append([i,k])
                else:
                    break
            for path in paths:
                yoko[path[0]][path[1]] = temp

for i in range(H):
    for j in range(W):
        if Ss[i][j] == "#" or tate[i][j] != 0:
            continue
        else:
            paths = [[i,j]]
            temp = 1
            for k in range(i+1, H):
                if Ss[k][j] == ".":
                    temp+=1
                    paths.append([k,j])
                else:
                    break
            for path in paths:
                tate[path[0]][path[1]] = temp

answer = 0
for i in range(H):
    for j in range(W):
        if answer < tate[i][j]+yoko[i][j]-1:
            answer = tate[i][j]+yoko[i][j]-1
print(answer)

Submission status: Accepted

Solution code:
h, w = map(int, input().split())
chiz = [[] for _ in range(w)]
for _ in range(h):
    tmp_list = input()
    for i in range(w):
        chiz[i].append(tmp_list[i])
rsw_w = [[0]*h for _ in range(w)]
rsw_h = [[0]*h for _ in range(w)]
for j in range(h):
    for i in range(w):
        if chiz[i][j] == '.':
            if i > 0:
                rsw_w[i][j] = rsw_w[i-1][j] + 1
            else:
                rsw_w[i][j] = 1
for j in range(h):
    for i in reversed(range(w)):
        if chiz[i][j] == '.':
            if i < w-1:
                rsw_w[i][j] = max(rsw_w[i][j],rsw_w[i+1][j])
for i in range(w):
    for j in range(h):
        if chiz[i][j] == '.':
            if j > 0:
                rsw_h[i][j] = rsw_h[i][j-1] + 1
            else:
                rsw_h[i][j] = 1
for i in range(w):
    for j in reversed(range(h)):
        if chiz[i][j] == '.':
            if j < h-1:
                rsw_h[i][j] = max(rsw_h[i][j],rsw_h[i][j+1])
res = 0
for j in range(h):
    for i in range(w):
       res = max(res,rsw_w[i][j]+rsw_h[i][j]-1)
print(res)

Submission status: Accepted

Solution code:
H,W = map(int,input().split())
S = [input().strip() for _ in range(H)]
X = [[0 for _ in range(W)] for _ in range(H)]
for i in range(H):
    j = 0
    cur = j
    while j<W:
        if S[i][j]==".":
            j += 1
        else:
            for k in range(cur,j):
                X[i][k] = j-cur
            j += 1
            cur = j
    for k in range(cur,W):
        X[i][k] = W-cur
Y = [[0 for _ in range(W)] for _ in range(H)]
for j in range(W):
    i = 0
    cur = i
    while i<H:
        if S[i][j]==".":
            i += 1
        else:
            for k in range(cur,i):
                Y[k][j] = i-cur
            i += 1
            cur = i
    for k in range(cur,H):
        Y[k][j] = H-cur
cmax = 0
for i in range(H):
    for j in range(W):
        if S[i][j]==".":
            cmax = max(cmax,X[i][j]+Y[i][j]-1)
print(cmax)

Submission status: Accepted

Solution code:
import numpy as np

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

S = np.array([[int(c == '.') for c in input()] for _ in range(H)])

up = S.copy()
down = S.copy()
left = S.copy()
right = S.copy()

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

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

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

Submission status: Accepted

Solution code:
#import sys
#import numpy as np
import math
#from fractions import Fraction
import itertools
from collections import deque
from collections import Counter
#import heapq
#from fractions  import gcd
#input=sys.stdin.readline
import bisect
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]=="#":
            l[i][j]=r[i][j]=u[i][j]=d[i][j]=0
        else: 
            l[i][j]=l[i][j-1]+1 if j!=0 else 1
            u[i][j]=u[i-1][j]+1 if i!=0 else 1
        if s[h-1-i][w-1-j]=="#":
            r[i][j]=d[i][j]=0
        else:
            r[i][j]=r[i][j-1]+1 if j!=0 else 1
            d[i][j]=d[i-1][j]+1 if i!=0 else 1
ans=0
for i in range(h):
    for j in range(w):
        res=l[i][j]+u[i][j]+r[h-1-i][w-1-j]+d[h-1-i][w-1-j]-3
        #print("##",i,j,"##",res)
        ans=max(res,ans)
print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# Created: Jul, 12, 2020 21:40:45 by Nobody
# $Author$
# $Date$
# $URL$
__giturl__ = "$URL$"


from collections import defaultdict
from collections import deque
from collections import OrderedDict
import itertools
from sys import stdin
input = stdin.readline


def main():
  H, W = list(map(int, input().split()))
  G = ['#'+input()[:-1]+'#' for _ in range(H)]
  G = ['#'*(W+2)] + G + ['#'*(W+2)]

  # print(G)
  U = [[0]*(W+2) for _ in range(H+2)]
  D = [[0]*(W+2) for _ in range(H+2)]
  L = [[0]*(W+2) for _ in range(H+2)]
  R = [[0]*(W+2) for _ in range(H+2)]
  # U and L
  for h in range(1, H+1):
    for w in range(1, W+1):
      if G[h][w] == '#':
        continue
      U[h][w] = U[h-1][w] + 1
      L[h][w] = L[h][w-1] + 1

  for h in range(H, 0, -1):
    for w in range(W, 0, -1):
      if G[h][w] == '#':
        continue
      D[h][w] = D[h+1][w] + 1
      R[h][w] = R[h][w+1] + 1

  max_ = 0
  for h in range(1, H+1):
    for w in range(1, W+1):
      max_ = max(max_, U[h][w]+L[h][w]+D[h][w]+R[h][w])

  print(max_ - 3)


if(__name__ == '__main__'):
  main()

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:
H, W = map(int, input().split())

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

L, R, U, B = [], [], [], []
for y in range(H):
    targets = [L, R]
    ranges = [range(W), range(W-1, -1, -1)]
    for target, rng in zip(targets, ranges):
        row = [0] * W
        c = -1
        for x in rng:
            if G[y][x] == "#":
                c = -1
            else:
                c += 1
            row[x] = c
        target.append(row)
for x in range(W):
    targets = [U, B]
    ranges = [range(H), range(H-1, -1, -1)]
    for target, rng in zip(targets, ranges):
        col = [0] * H
        c = -1
        for y in rng:
            if G[y][x] == "#":
                c = -1
            else:
                c += 1
            col[y] = c
        target.append(col)

max_light = 0
for y in range(H):
    for x in range(W):
        light = L[y][x] + R[y][x] + U[x][y] + B[x][y] + 1
        max_light = max(light, max_light)
print(max_light)

Submission status: Accepted

Solution code:
import numpy as np
h, w = map(int, input().split())
s = [list(input()) for i in range(h)]
li = [[0 if s[i][j] == "#" else 1 for j in range(w)] for i in range(h)]
l, r, u, d = np.array(li), np.array(li), np.array(li), np.array(li)
for i in range(1, h):
    u[i] *= (u[i - 1] + 1)
    d[-i - 1] *= (d[-i] + 1)
for i in range(1, w):
    l[:, i] *= (l[:, i - 1] + 1)
    r[:, -i - 1] *= (r[:, -i] + 1)
print((l + r + u + d - 3).max())

Submission status: Accepted

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

H,W = map(int,input().split())
S=np.array([list(input().rstrip("\n")) 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[-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 as np

h, w = map(int, input().split())
s = np.empty((h, w), dtype='i8')
for i in range(h):
    s[i] = [i == '.' for i in list(input())]

right = np.copy(s)
left = np.copy(s)
for i in range(1, w):
    right[:, -i-1] = (right[:, -i] + 1) * s[:, -i-1]
    left[:, i] = (left[:, i-1] + 1) * s[:, i]
up = np.copy(s)
down = np.copy(s)
for i in range(1, h):
    up[i] = (up[i-1] + 1) * s[i]
    down[-i-1] = (down[-i] + 1) * s[-i-1]

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

Submission status: Accepted

Solution code:
import numpy as np


def main():
    h, w = map(int, input().split())
    s = np.array([[i == "." for i in input()] for _ in range(h)], dtype=int)
    left = s.copy()
    right = s.copy()
    up = s.copy()
    down = s.copy()
    for i in range(w - 1):
        left[:, i + 1] = (left[:, i] + 1) * s[:, i + 1]
        right[:, -i - 2] = (right[:, -i - 1] + 1) * s[:, -i - 2]
    for i in range(h - 1):
        up[i + 1] = (up[i] + 1) * s[i + 1]
        down[-i - 2] = (down[-i - 1] + 1) * s[-i - 2]
    print((left + right + up + down).max() - 3)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
import numpy as np


def read():
    return sys.stdin.readline().rstrip()


def main():
    h, w = map(int, read().split())
    s = np.array([[i == "." for i in read()] for _ in range(h)], dtype=int)
    left = s.copy()
    right = s.copy()
    up = s.copy()
    down = s.copy()
    for i in range(w - 1):
        left[:, i + 1] = (left[:, i] + 1) * s[:, i + 1]
        right[:, -i - 2] = (right[:, -i - 1] + 1) * s[:, -i - 2]
    for i in range(h - 1):
        up[i + 1] = (up[i] + 1) * s[i + 1]
        down[-i - 2] = (down[-i - 1] + 1) * s[-i - 2]
    print((left + right + up + down).max() - 3)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
import numpy as np


def read():
    return sys.stdin.readline().rstrip()


def main():
    h, w = map(int, read().split())
    s = np.array([[i == "." for i in read()] for _ in range(h)], dtype=int)
    left = np.zeros((h, w), dtype=int)
    right = np.zeros((h, w), dtype=int)
    up = np.zeros((h, w), dtype=int)
    down = np.zeros((h, w), dtype=int)
    left[:, 0] = s[:, 0]
    right[:, -1] = s[:, -1]
    for i in range(w - 1):
        left[:, i + 1] = (left[:, i] + 1) * s[:, i + 1]
        right[:, -i - 2] = (right[:, -i - 1] + 1) * s[:, -i - 2]
    up[0] = s[0]
    down[-1] = s[-1]
    for i in range(h - 1):
        up[i + 1] = (up[i] + 1) * s[i + 1]
        down[-i - 2] = (down[-i - 1] + 1) * s[-i - 2]
    print((left + right + up + down).max() - 3)


if __name__ == '__main__':
    main()