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: Wrong Answer

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  h,w=LI()
  s=[S() 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):
    for j in range(w):
      if s[i][j]=='#':
        L[i][j]=0
        continue

      if i==0:
        U[i][j]=1

      if j==0:
        L[i][j]=1

      if i!=0 and j!=0:
        L[i][j]=L[i][j-1]+1
        U[i][j]=U[i-1][j]+1

  for i in range(h)[::-1]:
    for j in range(w)[::-1]:
      if s[i][j]=='#':
        R[i][j]=0
        continue

      if i==h-1:
        D[i][j]=1

      if j==w-1:
        R[i][j]=1

      if i!=h-1 and j!=w-1:
        R[i][j]=R[i][j+1]+1
        D[i][j]=D[i+1][j]+1

  ans=0
  for i in range(h):
    for j in range(w):
      ans=max(ans,R[i][j]+L[i][j]+U[i][j]+D[i][j]-min(R[i][j],1)-min(L[i][j],1)-min(U[i][j],1)-min(D[i][j],1)+1)

  return ans

# main()
print(main())

Submission status: Wrong Answer

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  h,w=LI()
  s=[S() 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):
    for j in range(w):
      if s[i][j]=='#':
        L[i][j]=0
        continue

      if i==0:
        U[i][j]=1

      if j==0:
        L[i][j]=1

      if i!=0 and j!=0:
        L[i][j]=L[i][j-1]+1
        U[i][j]=U[i-1][j]+1

  for i in range(h)[::-1]:
    for j in range(w)[::-1]:
      if s[i][j]=='#':
        R[i][j]=0
        continue

      if i==h-1:
        D[i][j]=1

      if j==w-1:
        R[i][j]=1

      if i!=h-1 and j!=w-1:
        R[i][j]=R[i][j+1]+1
        D[i][j]=D[i+1][j]+1

  ans=0
  for i in range(h):
    for j in range(w):
      ans=max(ans,R[i][j]+L[i][j]+U[i][j]+D[i][j]-3)

  return ans

# main()
print(main())

Submission status: Wrong Answer

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,queue,copy

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  h,w=LI()
  s=[S() for _ in range(h)]

  ans=0
  memo=[0 for _ in range(h)]
  for i in range(h):
    for j in range(w):
      if s[i][j]=='#':
        continue

      _ans=0
      if memo[i]==0:
        for a in range(j)[::-1]:
          if s[i][a]=='.':
            _ans+=1
          else:
            break
        for a in range(j,w):
          if s[i][a]=='.':
            _ans+=1
          else:
            break
        memo[i]=_ans
      else:
        _ans=memo[i]

      for a in range(i)[::-1]:
        if s[a][j]=='.':
          _ans+=1
        else:
          break
      for a in range(i+1,h):
        if s[a][j]=='.':
          _ans+=1
        else:
          break

      ans=max(ans,_ans)
  return ans

# main()
print(main())

Submission status: Wrong Answer

Solution code:
import numpy as np

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

S = np.ones([H+2, W+2], dtype=bool)
for h in range(H):
  S[h+1] = np.array(['.'] + list(input()) + ['.']) == '.'

dp1 = np.zeros([H+2, W+2, 2], dtype=int) # [up, left]
for h in range(H):
  dp1[h+1, :, 0] = (dp1[h, :, 0] + 1)*S[h+1]

for w in range(W):
  dp1[:, w+1, 1] = (dp1[:, w, 1] + 1)*S[:, w+1]

dp2 = np.zeros([H+2, W+2, 2], dtype=int) # [down, right]
for h in range(H, 0, -1):
  dp2[h, :, 0] = (dp2[h+1, :, 0] + 1)*S[h]

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

print(np.max(np.sum(dp1, axis=2)+np.sum(dp2, axis=2))-3)

Submission status: Wrong Answer

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

S = []
for i in range(H):
  S.append(list(input()))

dp = [[0] * W for h in range(H)]
dp1 = [[[0, 0] for w in range(W+1)] for h in range(H+1)]
for h in range(H):
  for w in range(W):
    if S[h][w] == '#':
      continue
    
    dp1[h+1][w+1] = [dp1[h][w][0]+1, dp1[h][w][1]+1]
    dp[h][w] = sum(dp1[h+1][w+1])


ans = 0
dp2 = [[[0, 0] for w in range(W+1)] for i in range(H+1)]
for h in range(H)[::-1]:
  for w in range(W)[::-1]:
    if S[h][w] == '#':
      continue

    dp2[h][w] = [dp2[h+1][w][0]+1, dp2[h][w+1][1]+1]
    dp[h][w] += sum(dp2[h][w])
    ans = max(ans, dp[h][w]-3)

print(ans)

Submission status: Wrong Answer

Solution code:
H,W = map(int,input().split())
S = [input().strip() for _ in range(H)]
A = [[[0,0] for _ in range(W)] for _ in range(H)]
for i in range(H):
    cnt = 0
    for j in range(W):
        if S[i][j]=="#":
            cnt = 0
        else:
            cnt += 1
            A[i][j-1][0] = cnt
for i in range(H):
    for j in range(W-2,-1,-1):
        A[i][j][0] = 0 if A[i][j][0]==0 else max(A[i][j][0],A[i][j-1][0])
for j in range(W):
    cnt = 0
    for i in range(H):
        if S[i][j]=="#":
            cnt = 0
        else:
            cnt += 1
            A[i][j][1] = cnt
for j in range(W):
    for i in range(H-2,-1,-1):
        A[i][j][1] = 0 if A[i][j][1]==0 else max(A[i][j][1],A[i+1][j][1])
cmax = 0
for i in range(H):
    for j in range(W):
        cmax = max(cmax,sum(A[i][j]))
print(cmax-1)

Submission status: Wrong Answer

Solution code:
H,W = map(int,input().split())
S = [input().strip() for _ in range(H)]
A = [[[0,0] for _ in range(W)] for _ in range(H)]
for i in range(H):
    cur = 0
    cnt = 0
    for j in range(W):
        if S[i][j]=="#":
            cur = j+1
            cnt = 0
        else:
            cnt += 1
            A[i][j-1][0] = cnt
for i in range(H):
    for j in range(W-2,-1,-1):
        A[i][j][0] = 0 if A[i][j]==0 else max(A[i][j][0],A[i][j+1][0])
for j in range(W):
    cur = 0
    cnt = 0
    for i in range(H):
        if S[i][j]=="#":
            cur = i+1
            cnt = 0
        else:
            cnt += 1
            A[i][j][1] = cnt
for j in range(W):
    for i in range(H-2,-1,-1):
        A[i][j][1] = 0 if A[i][j][1]==0 else max(A[i][j][1],A[i+1][j][1])
cmax = 0
for i in range(H):
    for j in range(W):
        cmax = max(cmax,sum(A[i][j]))
print(cmax-1)

Submission status: Wrong Answer

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

if __name__ == "__main__":

    U = [[-1 for _ in range(W)] for _ in range(H)]
    D = [[-1 for _ in range(W)] for _ in range(H)]
    R = [[-1 for _ in range(W)] for _ in range(H)]
    L = [[-1 for _ in range(W)] for _ in range(H)]
    for col in range(W):
        for row in range(0, H, 1):
            if grid[row][col] == '#':
                continue
            if row == 0:
                U[row][col] = 1
            else:
                U[row][col] = U[row-1][col]+1
    for col in range(W):
        for row in range(H-1, -1, -1):
            if grid[row][col] == '#':
                continue
            if row == H-1:
                D[row][col] = 1
            else:
                D[row][col] = D[row+1][col]+1
    for row in range(H):
        for col in range(0, W, 1):
            if grid[row][col] == '#':
                continue
            if col == 0:
                L[row][col] = 1
            else:
                L[row][col] = L[row][col-1]+1
    for row in range(H):
        for col in range(W-1, -1, -1):
            if grid[row][col] == '#':
                continue
            if col == W-1:
                R[row][col] = 1
            else:
                R[row][col] = R[row][col+1]+1
    
    ans = 0
    for row in range(H):
        for col in range(W):
            if grid[row][col] == '#':
                continue
            score = U[row][col]+D[row][col]+L[row][col]+R[row][col]-2
            if ans < score:
                ans = score
    print(ans)

Submission status: Wrong Answer

Solution code:
import re

H, W = map(int, input().split())
S = []
for _ in range(H):
    S.append(list(input()))
cnt = [[0]*W for _ in range(H)]
for i in range(H):
    c = 0
    for j in range(W):
        if S[i][j] == '.':
            c += 1
        else:
            c = 0
        cnt[i][j] = c
ans = []
for c in cnt:
    c = [i for i in re.split("(0)", "".join(map(str, c))) if i != '']
    a = []
    for c1 in c:
        c1 = list(c1)
        m = max(c1)
        a += [m]*len(c1)
    ans.append(a)

cnt = [[0]*H for _ in range(W)]
Sr = [list(x) for x in zip(*S)]
for j in range(W):
    c = 0
    for i in range(H):
        if Sr[j][i] == '.':
            c += 1
        else:
            c = 0
        cnt[j][i] = c
ans1 = []
for c in cnt:
    c = [i for i in re.split("(0)", "".join(map(str, c))) if i != '']
    a = []
    for c1 in c:
        c1 = list(c1)
        m = max(c1)
        a += [m]*len(c1)
    ans1.append(a)
ans1 = [list(x) for x in zip(*ans1)]
m = 0
for i in range(H):
    for j in range(W):
        ans[i][j] = int(ans[i][j]) + int(ans1[i][j])
        if m < ans[i][j]:
            m = ans[i][j]
print(m-1)

Submission status: Wrong Answer

Solution code:
import re

H, W = map(int, input().split())
S = []
for _ in range(H):
    S.append(list(input()))
cnt = [[0]*W for _ in range(H)]
for i in range(H):
    c = 0
    for j in range(W):
        if S[i][j] == '.':
            c += 1
        else:
            c = 0
        cnt[i][j] = c
ans = []
for c in cnt:
    c = [i for i in re.split("(0)", "".join(map(str, c))) if i != '']
    a = []
    for c1 in c:
        c1 = list(c1)
        m = max(c1)
        for _ in range(len(c1)):
            a.append(m)
    ans.append(a)

cnt = [[0]*H for _ in range(W)]
Sr = [list(x) for x in zip(*S)]
for j in range(W):
    c = 0
    for i in range(H):
        if Sr[j][i] == '.':
            c += 1
        else:
            c = 0
        cnt[j][i] = c
ans1 = []
for c in cnt:
    c = [i for i in re.split("(0)", "".join(map(str, c))) if i != '']
    a = []
    for c1 in c:
        c1 = list(c1)
        m = max(c1)
        for _ in range(len(c1)):
            a.append(m)
    ans1.append(a)
ans1 = [list(x) for x in zip(*ans1)]
m = 0
for i in range(H):
    for j in range(W):
        ans[i][j] = int(ans[i][j]) + int(ans1[i][j])
        if m < ans[i][j]:
            m = ans[i][j]
print(m-1)

Submission status: Wrong Answer

Solution code:
H,W = map(int,input().split())
mat = [(list(input())) for _ in range(H)]
L = [[0]*W for _ in range(H)]
R = [[0]*W for _ in range(H)]
D = [[0]*W for _ in range(H)]
U = [[0]*W for _ in range(H)]

for i in range(H):
    for j in range(W-1):
        if mat[i][j] != "#":
            if j == 0:
                L[i][j] = 1
            else:
                L[i][j] = L[i][j-1]+1
        else:
            L[i][j] = 0
for i in range(H):
    for j in range(W-1,-1,-1):
        if mat[i][j] != "#":
            if j == (W-1):
                R[i][j] = 1
            else:
                R[i][j] = R[i][j+1]+1
        else:
            R[i][j] = 0
for i in range(H-1,-1,-1):
    for j in range(W):
        if mat[i][j] != "#":
            if i == (H-1):
                D[i][j] = 1
            else:
                D[i][j] = D[i+1][j]+1
        else:
            D[i][j] = 0
for i in range(H-1):
    for j in range(W):
        if mat[i][j] != "#":
            if i == 0:
                U[i][j] = 1
            else:
                U[i][j] = U[i-1][j]+1
        else:
            U[i][j] = 0
ans = 0
for i in range(H):
    for j in range(W):
        tmp = L[i][j]+R[i][j]+D[i][j]+U[i][j]-3
        if ans < tmp:
            ans = tmp
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
from collections import deque
import numpy as np
input = sys.stdin.readline
H, W = [int(x) for x in input().strip().split()]
S = np.zeros(H * W).reshape(H, W)
ans = np.zeros(H * W).reshape(H, W)

for h in range(H):
    s = [0 if i == '.' else -1 for i in input().strip()]
    S[h] = np.array(s)

vc = [0] * W
vq = [deque([]) for _ in range(W)]
max_ans = 0
for i, s in enumerate(S):
    c = 0
    q = deque([])
    for k, j in enumerate(s):
        if j == 0:
            c += 1
            q.append(k)
            vc[k] += 1
            vq[k].append(i)
            continue
        for qq in q:
            ans[i, qq] += c
            max_ans = max(max_ans, ans[i, qq])
        for vqq in vq[k]:
            ans[vqq, k] += c
            max_ans = max(max_ans, ans[vqq, k])
        q = deque([])
        vq[k] = deque([])
        c = 0
        vc[k] = 0
    else:
        for qq in q:
            ans[i, qq] += c
            max_ans = max(max_ans, ans[i, qq])
        for vqq in vq[k]:
            ans[vqq, k] += c
            max_ans = max(max_ans, ans[vqq, k])

print(int(max_ans-1))

Submission status: Wrong Answer

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

def solve():
    ans = 0
    for i in range(H):
        for j in range(W):
            if ans == H*W-1:
                return ans
            if mat[i][j] == ".":
                up = i
                down = H-(up+1)
                left = j
                right = W-(left+1)
                count = 1
                for k in range(up):
                    if mat[i-k-1][j] == "#":
                        break
                    else:
                        count += 1
                for k in range(down):
                    if mat[i+k+1][j] == "#":
                        break
                    else:
                        count += 1
                for k in range(left):
                    if mat[i][j-k-1] == "#":
                        break
                    else:
                        count += 1
                for k in range(right):
                    if mat[i][j+k+1] == "#":
                        break
                    else:
                        count += 1
                if count > ans:
                    ans = count
    return ans
print(solve())

Submission status: Wrong Answer

Solution code:
H,W = map(int,input().split())
mat = [list(input()) for _ in range(H)]
ans = 0
for i in range(H):
    for j in range(W):
        if ans == H*W-1:
            break
        if mat[i][j] == ".":
            up = i
            down = H-(up+1)
            left = j
            right = W-(left+1)
            count = 1
            for k in range(up):
                if mat[i-k-1][j] == "#":
                    break
                else:
                    count += 1
            for k in range(down):
                if mat[i+k+1][j] == "#":
                    break
                else:
                    count += 1
            for k in range(left):
                if mat[i][j-k-1] == "#":
                    break
                else:
                    count += 1
            for k in range(right):
                if mat[i][j+k+1] == "#":
                    break
                else:
                    count += 1
            if count > ans:
                ans = count
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np

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

maze_x = [input() for _ in range(H)]
maze_y = [''.join(x) for x in zip(*maze_x)]

def count_light(maze, W, H):
    cnt = [[0]*W for _ in range(H)]
    for hh in range(H):
        lst1 = [i for i in maze[hh].split('#') if i != '']
        lst2 = [i for i in maze[hh].split('.') if i != '']
        lst2.append('#')
        ww = 0
        k1 = 0
        k2 = 0
        if maze[hh][0]=='#':
            ww += len(lst2[0])
            k2 += 1
          
        while len(lst1)>k1:
            ln = len(lst1[k1])
            cnt[hh][ww:ww+ln] = [ln]*ln
            k1 += 1

            ln = len(lst2[k2])
            cnt[hh][ww:ww+ln] = [0]*ln
            k2 += 1
            ww += ln
    return cnt
cnt = (np.array(count_light(maze_x, W, H)) + np.array(count_light(maze_y, H, W)).T -1)

print(max([max(cnt[i]) for i in range(H)]))

Submission status: Wrong Answer

Solution code:
import sys
from collections import deque
input = sys.stdin.readline
H, W = [int(x) for x in input().strip().split()]
S = [0 for _ in range(H)]
ans = [[0] * W for h in range(H)]

for h in range(H):
    S[h] = list(input().strip())

vc = [0] * W
vq = [deque([]) for _ in range(W)]
max_ans = 0
for i, s in enumerate(S):
    c = 0
    q = deque([])
    for k, j in enumerate(s):
        if j == '.':
            c += 1
            q.append(k)
            vc[k] += 1
            vq[k].append(i)
            continue
        for qq in q:
            ans[i][qq] += c
            max_ans = max(max_ans, ans[i][qq])
        for vqq in vq[k]:
            ans[vqq][k] += c
            max_ans = max(max_ans, ans[vqq][k])
        q = deque([])
        vq[k] = deque([])
        c = 0
        vc[k] = 0
    else:
        for qq in q:
            ans[i][qq] += c
            max_ans = max(max_ans, ans[i][qq])
        for vqq in vq[k]:
            ans[vqq][k] += c
            max_ans = max(max_ans, ans[vqq][k])

print(max_ans-1)

Submission status: Wrong Answer

Solution code:
import numpy as np
H,W = map(int,input().split())
S = [list(input()) for _ in range(H)]
L = np.zeros((H,W))
R = np.zeros((H,W))
U = np.zeros((H,W))
D = np.zeros((H,W))
for i in range(H):
    for j in range(W):
        if j == 0:
            if S[i][j] == "#":
                L[i,j] = -1
            continue
        if S[i][j] == ".":
            L[i,j] += L[i,j-1]+1
        else:
            L[i,j] = -1
    for j in reversed(range(W)):
        if j == W-1:
            if S[i][j] == "#":
                R[i,j] = -1
            continue
        if S[i][j] == ".":
            R[i,j] += R[i,j+1]+1
        else:
            R[i,j] = -1
for j in range(W):
    for i in range(H):
        if i == 0:
            if S[i][j] == "#":
                U[i,j] = -1
            continue
        if S[i][j] == ".":
            U[i,j] += U[i-1,j]+1
        else:
            U[i,j] = -1
    for i in reversed(range(H)):
        if i == H-1:
            if S[i][j] == "#":
                D[i,j] = -1
            continue
        if S[i][j] == ".":
            D[i,j] += D[i+1,j]+1
        else:
            D[i,j] = -1
su = L+R+U+D
#print(L,R,U,D,sep="\n")
print(su)
print(int(np.amax(su)+1))

Submission status: Wrong Answer

Solution code:
h,w=map(int,input().split())
grid=[None]*h

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

yoko=[[0 for i in range(w)] for j in range(h)]
tate=[[0 for i in range(w)] for j in range(h)]

for i in range(h):
  s=grid[i]
  left=0
  right=0
  while left<len(s):
    if s[left]=="#":
      left+=1
      right=left
      continue
    while right+1<w and s[right+1]==".":
      right+=1
  
    for j in range(left,right+1):
      yoko[i][j]=right-left
      
    left=right+1
    right=left
    
for i in range(w):
  up=0
  down=0
  while up<h:
    if grid[down][i]=="#":
      up+=1
      down=up
      continue
    while down+1<h and grid[down+1][i]==".":
      down+=1
    for j in range(up,down+1):
      tate[j][i]=down-right
    up=down+1
    down=up
    
ans=0
for i in range(h):
  for j in range(w):
    if grid[i][j]==".":
      ans=max(ans,tate[i][j]+yoko[i][j])
      
print(ans)

Submission status: Wrong Answer

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


def calc(x, isTrans):
    if isTrans:
        y = np.copy(x.T)
    else:
        y = np.copy(x)

    for i in range(len(y)):
        xxx = np.copy(y[i])
        tmp_l = np.arange(len(xxx))
        tmp_l[xxx > 0] = 0
        np.maximum.accumulate(tmp_l, out=tmp_l)
        left = tmp_l

        xxx_reverse = xxx[::-1]
        tmp_r = np.arange(len(xxx_reverse))
        tmp_r[xxx_reverse > 0] = 0
        np.maximum.accumulate(tmp_r, out=tmp_r)
        right = len(xxx)-tmp_r[::-1]-1

        y[i] = right-left-1
        y[i][xxx == 0] = 0

    if isTrans:
        return np.transpose(y)
    else:
        return y


if __name__ == "__main__":
    h, w = map(int, readline().split())
    room = np.zeros((h+2, w+2), dtype=np.bool)
    room[1:-1, 1:] = (np.frombuffer(read(h * (w + 1)),
                                    dtype="S1") == b'.').reshape((h, w + 1))

    a = calc(room, True)
    b = calc(room, False)
    ans = (a + b).max() - 1
    print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np

def convert(L):
    dp = np.empty_like(L)
    for i in range(L.shape[0]):
        l=L[i]
        start=0
        end=0
        sum_=0
        for j in range(L.shape[1]):
            if l[j] == 1:
                end += 1
                sum_ += 1
            elif l[j] == 0 and sum_ !=0:
                dp[i][start:end] = sum_
                sum_= 0
                start = end + 1
            elif l[j] == 0 and sum_ ==0:
                start += 1
                end += 1
            #print(i,j,start,end,sum_,l[j])
        if sum_!=0:
            dp[i][start:end+1] = sum_  
    return dp

H,W=map(int,input().split())
L= np.zeros((H,W))
for i in range(H):
    L[i]=list(map(lambda x: 0 if x=="#" else 1,list(input()) ))

dp1 = convert(L).astype('int')
dp2 = convert(L.T).T.astype('int')
ans = dp1+dp2-1
print(ans.max())

Submission status: Wrong Answer

Solution code:
h,w = map(int,input().split())
tate = [[0]*w for i in range(h)]
yoko = [[0]*w for i in range(h)]
s = [str(input()) for i in range(h)]

for i in range(h):
    cnt = 0
    now = 0
    for j in range(w):
        if s[i][j] == ".":
            cnt += 1
        else:
            for k in range(now,cnt+1):
                yoko[i][k] = cnt
            cnt = 0
for i in range(w):
    cnt = 0
    now = 0
    for j in range(h):
        if s[j][i] == ".":
            cnt += 1
        else:
            for k in range(now,cnt+1):
                tate[k][i] = cnt
            cnt = 0
ans = 0
for i in range(h):
    for j in range(w):
        ans = max(ans,tate[i][j]+yoko[i][j])
print(ans)

Submission status: Wrong Answer

Solution code:
#d
h,w = map(int,input().split())
s=[]
for i in range(h):
    s.append(list(input()) )
    
l=[[0]*w for _ in range(h)]
for i in range(h):
    count=0
    for j in range(w):
        if s[i][j] ==".":
            count+=1
        else:
            count=0
        l[i][j]=count
        
r=[[0]*w for _ in range(h)]
for i in range(h-1,-1,-1):
    count=0
    for j in range(w-1,-1,-1):
        if s[i][j] ==".":
            count+=1
        else:
            count=0
        r[i][j]=count
                
d=[[0]*w for _ in range(h)]
for j in range(w-1,-1,-1):
    count=0
    for i in range(h-1,-1,-1):
        if s[i][j] ==".":
            count+=1
        else:
            count=0
        d[i][j]=count
                
u=[[0]*w for _ in range(h)]
for j in range(w):
    count=0
    for i in range(h):
        if s[i][j] ==".":
            count+=1
        else:
            count=0
        u[i][j]=count

ans=[[0]*w for _ in range(h)]
for i in range(h):
    for j in range(w):
        ans[i][j] = l[i][j]+ r[i][j]+ u[i][j]+ d[i][j]-3
max( max(ans[i]) for i in range(h))

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**9)
def input():
    return sys.stdin.readline().rstrip()

def main():
    H,W=map(int,input().split())
    S=[list(input()) for i in range(H)]
    ans=0
    for y in range(H):
        for x in range(W):
            c = 1
            if S[y][x]=='.':
                for i in range(1,y+1):
                    if S[i][x] == '.':
                       c+=1
                    else:
                       break
                for i in range(y+1,H):
                    if S[i][x] == '.':
                       c+=1
                    else:
                       break
                for i in range(1,x+1):
                    if S[y][i] == '.':
                       c += 1
                    else:
                       break
                for i in range(x+1,W):
                    if S[y][i] == '.':
                       c += 1
                    else:
                       break
            ans=max(ans,c)
    print(ans)
                

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

S = []
for i in range(H):
    S.append(input())

#print(S)
max_cnt = 0
for i in range(H):
    for j in range(W):
        state = S[i][j]
        cnt = 0 if state == '#' else 1
        #上
        for k in range(max(-1,i-1),-1,-1):
            if S[k][j] == '#':
                break
            else:
                cnt += 1
        #if (i,j) == (1,1): print(cnt)

        #下
        for k in range(min(H,i+1),H):
            if S[k][j] == '#':
                break
            else:
                cnt += 1
        #if (i,j) == (1,1): print(cnt)

        #右
        for k in range(min(W,j+1),W):
            if S[i][k] == '#':
                break
            else:
                cnt += 1
        #if (i,j) == (1,1): print(cnt)

        #左
        for k in range(max(-1,j-1),-1,-1):
            if S[i][k] == '#':
                break
            else:
                cnt += 1
        if max_cnt < cnt:
            max_cnt = cnt
        #if (i,j) == (1,1): print(cnt)
print(max_cnt)

Submission status: Wrong Answer

Solution code:
h,w=map(int,input().split())
s=['#'*(w+2)]+['#'+input()+'#' for _ in range(h)]+['#'*(w+2)]
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)]
for i in range(1,h+1):
  for j in range(1,w+1):
    if s[i][j]=='.':
      l[i][j]=l[i][j-1]+1
      r[i][w+1-j]=r[i][w+2-j]+1
for i in range(1,w+1):
  for j in range(1,h+1):
    if s[j][i]=='.':
      u[j][i]=u[j-1][i]+1
      d[h+1-j][i]=r[h+2-j][i]+1
m=0
for i in range(1,h+1):
  for j in range(1,w+1):
    m=max(m,u[i][j]+d[i][j]+l[i][j]+r[i][j]-3)
print(m)

Submission status: Wrong Answer

Solution code:
h,w=map(int,input().split())
meiro=[list(input()) for i in range(h)]
for i in range(h):
    meiro[i].insert(w,"*")
    meiro[i].insert(0,"*")
meiro.insert(0,["*"]*(w+2))
meiro.append(["*"]*(w+2))
#print(meiro)
cnt=[[-1]*(w+2) for i in range(h+2)]
from collections import deque
quest=deque([])#最初に見る場所

for i in range(1,h+1):
    for j in range(1,w+1):
        if meiro[i][j]==".":
            quest.append([i,j])
            cnt[i][j]=1
idou=[[0,1],[0,-1],[1,1],[1,-1],[-1,1],[-1,-1],[1,0],[-1,0]]
while len(quest)!=0:
    see=quest.popleft()
    for i in idou:
        if meiro[see[0]+i[0]][see[1]+i[1]]==".":
            cnt[see[0]][see[1]]+=1
#print(cnt)
c=[]
for i in range(1,h+1):
  c.append(max(cnt[i]))
print(max(c))

Submission status: Wrong Answer

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

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 h in range(H):
  for w in range(W):
    if field[h][w] == "#":
      L[h][w] = 0
      U[h][w] = 0
    elif w == 0:
      L[h][w] = 1
    else:
      L[h][w] = L[h][w-1] + 1
    if h == 0:
      U[h][w] = 1
    else:
      U[h][w] = U[h-1][w] + 1
#print(L)
for h in range(H):
  for w in range(W-1,-1,-1):
    if field[h][w] == "#":
      R[h][w] = 0
    elif w == W-1:
      R[h][w] = 1
    else:
      R[h][w] = R[h][w+1] + 1
#print(R)
for h in range(H-1,-1,-1):
  for w in range(W):
    if field[h][w] == "#":
      D[h][w] = 0
    elif h == H-1:
      D[h][w] = 1
    else:
      D[h][w] = D[h+1][w] + 1
#print(D)     
#print(U)
ans = 0
for h in range(H):
  for w in range(W):
    ans = max(ans,L[h][w] + R[h][w] + D[h][w] + U[h][w] - 3)
print(ans)

Submission status: Wrong Answer

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

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 h in range(H):
  for w in range(W):
    if field[h][w] == "#":
      L[h][w] = 0
    elif w == 0:
      L[h][w] = 1
    else:
      L[h][w] = L[h][w-1] + 1
#print(L)
for h in range(H):
  for w in range(W-1,-1,-1):
    if field[h][w] == "#":
      R[h][w] = 0
      U[h][w] = 0
    elif w == W-1:
      R[h][w] = 1
    else:
      R[h][w] = R[h][w+1] + 1
    if h == 0:
      U[h][w] = 1
    else:
      U[h][w] = U[h-1][w] + 1
#print(R)
for h in range(H-1,-1,-1):
  for w in range(W):
    if field[h][w] == "#":
      D[h][w] = 0
    elif h == H-1:
      D[h][w] = 1
    else:
      D[h][w] = D[h+1][w] + 1
#print(D)     
#print(U)
ans = 0
for h in range(H):
  for w in range(W):
    ans = max(ans,L[h][w] + R[h][w] + D[h][w] + U[h][w] - 3)
print(ans)