Problem: 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.

Submission attempts (in order):
import sys
input = sys.stdin.readline
h,w = map(int,input().split())
l=['
ans = 1

def dfs(x,y,h,w):
  cnt = 1
  for i in range(1,w+2):
    if l[x+i][y] == '.':
      cnt += 1
    else:
      break
  for i in range(1,w+2):
    if l[x-i][y] == '.':
      cnt += 1
    else:
      break
  for i in range(1,h+2):
    if l[x][y+i] == '.':
      cnt += 1
    else:
      break
  for i in range(1,h+2):
    if l[x][y-i] == '.':
      cnt += 1
    else:
      break
  return cnt
for i in range(h+2):
  for j in range(w+2):
    if l[i][j] == '.':
      ans = max(ans,dfs(i,j,h,w))
print(ans)

import sys
sys.setrecursionlimit(1000000)
input = sys.stdin.readline
h,w = map(int,input().split())
l=['
dp = [[[0]*2 for i in range(w+2)] for i in range(h+2)]
cnt = 0
ans = 0

def dfsw(x,y,cnt):
  if l[x][y+1] == '.':
    cnt += 1
    dp[x][y][0] = dfsw(x,y+1,cnt)
    return dp[x][y][0]
  else:
    dp[x][y][0] = cnt
    return dp[x][y][0]

def dfsh(x,y,cnt):
  if l[x+1][y] == '.':
    cnt += 1
    dp[x][y][1] = dfsh(x+1,y,cnt)
    return dp[x][y][1]
  else:
    dp[x][y][1] = cnt
    return dp[x][y][1]

for i in range(h+2):
  for j in range(w+2):
    if l[i][j] == '.' and dp[i][j][0] == 0:
      dfsw(i,j,1)
for i in range(h+2):
  for j in range(w+2):
    if l[i][j] == '.' and dp[i][j][1] == 0:
      dfsh(i,j,1)
    
for i in range(h+2):
  for j in range(w+2):
    if l[i][j] == '.':
      ans = max(ans, sum(dp[i][j]) - 1)
print(ans)

import sys
input = sys.stdin.readline
h,w = map(int,input().split())
l=['
ans = 1

for i in range(h+2):
  for j in range(w+2):
    if l[i][j] == '.':
      cnt = 1
      for k in range(1,w+2):
        if l[i+k][j] == '.':
          cnt += 1
        else:
          break
      for k in range(1,w+2):
        if l[i-k][j] == '.':
   	      cnt += 1
        else:
          break
      for k in range(1,h+2):
        if l[i][j+k] == '.':
          cnt += 1
        else:
          break
      for k in range(1,h+2):
        if l[i][j-k] == '.':
          cnt += 1
        else:
          break
      ans = max(ans,cnt)
print(ans)

h,w = map(int,input().split())
l=['
ans = 1

def dfs(x,y,h,w):
  cnt = 1
  for i in range(1,w+2):
    if l[x+i][y] == '.':
      cnt += 1
    else:
      break
  for i in range(1,w+2):
    if l[x-i][y] == '.':
      cnt += 1
    else:
      break
  for i in range(1,h+2):
    if l[x][y+i] == '.':
      cnt += 1
    else:
      break
  for i in range(1,h+2):
    if l[x][y-i] == '.':
      cnt += 1
    else:
      break
  return cnt
for i in range(h+2):
  for j in range(w+2):
    if l[i][j] == '.':
      ans = max(ans,dfs(i,j,h,w))
print(ans)

import sys
sys.setrecursionlimit(1000000)
input = sys.stdin.readline
h,w = map(int,input().split())
l=['
dp = [[[0]*2 for i in range(w+2)] for i in range(h+2)]
cnt = 0
ans = 0

def dfsw(x,y,cnt):
  if l[x][y+1] == '.':
    cnt += 1
    dp[x][y][0] = dfsw(x,y+1,cnt)
    return dp[x][y][0]
  else:
    dp[x][y][0] = cnt
    return dp[x][y][0]

for i in range(h+2):
  for j in range(w+2):
    if l[i][j] == '.' and dp[i][j][0] == 0:
      dfsw(i,j,1)
    
for i in range(h+2):
  for j in range(w+2):
    if l[i][j] == '.':
      ans = max(ans, sum(dp[i][j]) - 1)
print(ans)

import sys
sys.setrecursionlimit(1000000)
input = sys.stdin.readline
h,w = map(int,input().split())
l=['
dp = [[[0]*2 for i in range(w+2)] for i in range(h+2)]
cnt = 0
ans = 0

def dfsw(x,y,cnt):
  if l[x][y+1] == '.':
    cnt += 1
    dp[x][y][0] = dfsw(x,y+1,cnt)
    return dp[x][y][0]
  else:
    dp[x][y][0] = cnt
    return dp[x][y][0]

def dfsh(x,y,cnt):
  if l[x+1][y] == '.':
    cnt += 1
    dp[x][y][1] = dfsh(x+1,y,cnt)
    return dp[x][y][1]
  else:
    dp[x][y][1] = cnt
    return dp[x][y][1]

for i in range(h+2):
  for j in range(w+2):
    if l[i][j] == '.':
      if dp[i][j][0] == 0:
        dfsw(i,j,1)
      if dp[i][j][1] == 0:
        dfsh(i,j,1)
      ans = max(ans, sum(dp[i][j]) - 1)
print(ans)

import numpy as np
import sys
sys.setrecursionlimit(1000000)
input = sys.stdin.readline
h,w = map(int,input().split())
l=['
dp = np.zeros((h+2,w+2,2),dtype=int)
cnt = 0
ans = 0

def dfsw(x,y,cnt):
  if l[x][y+1] == '.':
    cnt += 1
    dp[x,y,0] = dfsw(x,y+1,cnt)
    return dp[x,y,0]
  else:
    dp[x,y,0] = cnt
    return dp[x,y,0]

def dfsh(x,y,cnt):
  if l[x+1][y] == '.':
    cnt += 1
    dp[x,y,1] = dfsh(x+1,y,cnt)
    return dp[x,y,1]
  else:
    dp[x,y,1] = cnt
    return dp[x,y,1]

for i in range(h+2):
  for j in range(w+2):
    if l[i][j] == '.':
      if dp[i,j,0] == 0:
        dfsw(i,j,1)
      if dp[i,j,1] == 0:
        dfsh(i,j,1)
      ans = max(ans, sum(dp[i,j]) - 1)
print(ans)

h,w = map(int,input().split())
l=['
dp = [[[0]*4 for i in range(w+2)] for i in range(h+2)]
ans = 0

for i in range(h+2):
  for j in range(w+2):
     if l[i][j] == '#':
      dp[i][j][0] = 0
     else:
      dp[i][j][0] = dp[i][j-1][0] + 1
for i in range(h+2):
  for j in range(w+1,0,-1):
     if l[i][j] == '#':
      dp[i][j][1] = 0
     else:
      dp[i][j][1] = dp[i][j+1][1] + 1
for i in range(h+2):
  for j in range(w+2):
     if l[i][j] == '#':
      dp[i][j][2] = 0
     else:
      dp[i][j][2] = dp[i-1][j][2] + 1
for i in range(h+1,0,-1):
  for j in range(w+2):
     if l[i][j] == '#':
      dp[i][j][3] = 0
     else:
      dp[i][j][3] = dp[i+1][j][3] + 1
for i in range(h+2):
  for j in range(w+2):
    if l[i][j] == '.':
      ans = max(ans, sum(dp[i][j]) - 3)
print(ans)

import sys
input = sys.stdin.readline
h,w = map(int,input().split())
l=['
dp = [[[0]*4 for i in range(w+2)] for i in range(h+2)]
ans = 0

for i in range(h+2):
  for j in range(w+2):
     if l[i][j] == '#':
      dp[i][j][0] = 0
     else:
      dp[i][j][0] = dp[i][j-1][0] + 1
for i in range(h+2):
  for j in range(w+1,0,-1):
     if l[i][j] == '#':
      dp[i][j][1] = 0
     else:
      dp[i][j][1] = dp[i][j+1][1] + 1
for i in range(h+2):
  for j in range(w+2):
     if l[i][j] == '#':
      dp[i][j][2] = 0
     else:
      dp[i][j][2] = dp[i-1][j][2] + 1
for i in range(h+1,0,-1):
  for j in range(w+2):
     if l[i][j] == '#':
      dp[i][j][3] = 0
     else:
      dp[i][j][3] = dp[i+1][j][3] + 1
for i in range(h+2):
  for j in range(w+2):
    if l[i][j] == '.':
      ans = max(ans, sum(dp[i][j]) - 3)
print(ans)

h,w = map(int,input().split())
l=['
dp = [[[0]*2 for i in range(w+2)] for i in range(h+2)]
cnt = 0
ans = 0

def dfsw(x,y,cnt):
  if l[x][y+1] == '.':
    cnt += 1
    dp[x][y][0] = dfsw(x,y+1,cnt)
    return dp[x][y][0]
  else:
    dp[x][y][0] = cnt
    return dp[x][y][0]

def dfsh(x,y,cnt):
  if l[x+1][y] == '.':
    cnt += 1
    dp[x][y][1] = dfsh(x+1,y,cnt)
    return dp[x][y][1]
  else:
    dp[x][y][1] = cnt
    return dp[x][y][1]

for i in range(h+2):
  for j in range(w+2):
    if l[i][j] == '.' and dp[i][j][0] == 0:
      dfsw(i,j,1)
for i in range(h+2):
  for j in range(w+2):
    if l[i][j] == '.' and dp[i][j][1] == 0:
      dfsh(i,j,1)
    
for i in range(h+2):
  for j in range(w+2):
    if l[i][j] == '.':
      ans = max(ans, sum(dp[i][j]) - 1)
print(ans)

import numpy as np
h,w = map(int,input().split())
ar = np.array([list(input()) for _ in range(h)]) == '.'
#print(ar)
l = np.zeros((h,w),dtype=int)
r = np.zeros((h,w),dtype=int)
u = np.zeros((h,w),dtype=int)
d = np.zeros((h,w),dtype=int)

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

Verdicts: Wrong Answer

Time Limit Exceeded

Wrong Answer

Wrong Answer

Wrong Answer

Time Limit Exceeded

Time Limit Exceeded

Time Limit Exceeded

Time Limit Exceeded

Runtime Error

Accepted