Buggy python submission (verdict: Time Limit Exceeded):

H, W = map(int, input().split())
S = ["#" * (W + 2)] + ["#" + input() + "#" for _ in range(H)] + ["#" * (W + 2)]

LEFT = [[0 for j in range(W+2)] for i in range(H+2)]
RIGHT = [[0 for j in range(W+2)] for i in range(H+2)]
UP = [[0 for j in range(W+2)] for i in range(H+2)]
DOWN = [[0 for j in range(W+2)] for i in range(H+2)]

for h in range(H+2):
  for w in range(W+2):
    if S[h][w] == ".":
      LEFT[h][w] = LEFT[h][w-1] + 1
    else:
      LEFT[h][w] = 0

for h in range(H+2):
  for w in range(W+2)[::-1]:
    if S[h][w] == ".":
      RIGHT[h][w] = RIGHT[h][w+1] + 1
    else:
      RIGHT[h][w] = 0

for h in range(H+2)[::-1]:
  for w in range(W+2):
    if S[h][w] == ".":
      UP[h][w] = UP[h+1][w] + 1
    else:
      UP[h][w] = 0

for h in range(H+2):
  for w in range(W+2):
    if S[h][w] == ".":
      DOWN[h][w] = DOWN[h-1][w] + 1
    else:
      DOWN[h][w] = 0

ans = -1

for h in range(H+2):
  for w in range(W+2):
    value = RIGHT[h][w] + LEFT[h][w] + UP[h][w] + DOWN[h][w] - 3
    ans = max(ans, value)

print(ans)

Fixed submission:

H, W = map(int, input().split())
S = ["#" * (W + 2)] + ["#" + input() + "#" for _ in range(H)] + ["#" * (W + 2)]

LEFT = [[0 for j in range(W+2)] for i in range(H+2)]
RIGHT = [[0 for j in range(W+2)] for i in range(H+2)]
UP = [[0 for j in range(W+2)] for i in range(H+2)]
DOWN = [[0 for j in range(W+2)] for i in range(H+2)]

for h in range(H+2):
  for w in range(W+2):
    if S[h][w] == ".":
      LEFT[h][w] = LEFT[h][w-1] + 1
    else:
      LEFT[h][w] = 0

for h in range(H+2):
  for w in range(W+2)[::-1]:
    if S[h][w] == ".":
      RIGHT[h][w] = RIGHT[h][w+1] + 1
    else:
      RIGHT[h][w] = 0

for h in range(H+2)[::-1]:
  for w in range(W+2):
    if S[h][w] == ".":
      UP[h][w] = UP[h+1][w] + 1
    else:
      UP[h][w] = 0

for h in range(H+2):
  for w in range(W+2):
    if S[h][w] == ".":
      DOWN[h][w] = DOWN[h-1][w] + 1
    else:
      DOWN[h][w] = 0

ans = -1

for h in range(H+2):
  for w in range(W+2):
    value = RIGHT[h][w] + LEFT[h][w] + UP[h][w] + DOWN[h][w] - 3
    ans = max(ans, value)

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):

H, W = map(int, input().split())
edges = [["#" for i in range(W+2)]] + [["#"] + [None for i in range(W)] + ["#"] for j in range(H)] + [["#" for i in range(W+2)]]
right = [[None for i in range(H+2)] for j in range(W+2)]
left = [[None for i in range(H+2)] for j in range(W+2)]
up = [[None for i in range(H+2)] for j in range(W+2)]
down = [[None for i in range(H+2)] for j in range(W+2)]

for i in range(1, H+1):
  S = input()
  for j in range(1, W+1):
    edges[i][j] = S[j-1]

def dfs(x, y):
  flag = 1

  for next in [(x+1, y), (x-1, y), (x, y+1), (x, y-1)]:
    a, b = next
    while edges[b][a] == ".":
      if x - a > 0:
        if left[x][y]:
          flag += left[x][y]
          a -= left[x][y]
          break
        a -= 1
      elif x - a < 0:
        if right[x][y]:
          flag += right[x][y]
          a += right[x][y]
          break
        a += 1
      elif y - b > 0:
        if down[x][y]:
          flag += down[x][y]
          b -= down[x][y]
          break
        b -= 1
      elif y - b < 0:
        if up[x][y]:
          flag += up[x][y]
          b += up[x][y]
          break
        b += 1
      flag += 1

    if x - a > 0:
      left[x][y] = abs(x - a)
    elif x - a < 0:
      right[x][y] = abs(x - a)
    elif y - b > 0:
      down[x][y] = abs(y - b)
    elif y - b < 0:
      up[x][y] = abs(y - b)
  
  return flag

ans = -1
for h in range(1, H+1):
  for w in range(1, W+1):
    if edges[h][w] == "#":
      continue
    ans = max(ans, dfs(w, h))

print(ans)

Fixed submission:

H, W = map(int, input().split())
S = ["#" * (W + 2)] + ["#" + input() + "#" for _ in range(H)] + ["#" * (W + 2)]

LEFT = [[0 for j in range(W+2)] for i in range(H+2)]
RIGHT = [[0 for j in range(W+2)] for i in range(H+2)]
UP = [[0 for j in range(W+2)] for i in range(H+2)]
DOWN = [[0 for j in range(W+2)] for i in range(H+2)]

for h in range(H+2):
  for w in range(W+2):
    if S[h][w] == ".":
      LEFT[h][w] = LEFT[h][w-1] + 1
    else:
      LEFT[h][w] = 0

for h in range(H+2):
  for w in range(W+2)[::-1]:
    if S[h][w] == ".":
      RIGHT[h][w] = RIGHT[h][w+1] + 1
    else:
      RIGHT[h][w] = 0

for h in range(H+2)[::-1]:
  for w in range(W+2):
    if S[h][w] == ".":
      UP[h][w] = UP[h+1][w] + 1
    else:
      UP[h][w] = 0

for h in range(H+2):
  for w in range(W+2):
    if S[h][w] == ".":
      DOWN[h][w] = DOWN[h-1][w] + 1
    else:
      DOWN[h][w] = 0

ans = -1

for h in range(H+2):
  for w in range(W+2):
    value = RIGHT[h][w] + LEFT[h][w] + UP[h][w] + DOWN[h][w] - 3
    ans = max(ans, value)

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):

H, W = map(int, input().split())
edges = [["#" for i in range(W+2)]] + [["#"] + [None for i in range(W)] + ["#"] for j in range(H)] + [["#" for i in range(W+2)]]


for i in range(1, H+1):
  S = input()
  for j in range(1, W+1):
    edges[i][j] = S[j-1]

def dfs(x, y):
  flag = 1

  for next in [(x+1, y), (x-1, y), (x, y+1), (x, y-1)]:
    a, b = next
    while edges[b][a] == ".":
      # 直線をキャシュする？
      flag += 1
      if x - a > 0:
        a -= 1
      elif x - a < 0:
        a += 1
      elif y - b > 0:
        b -= 1
      elif y - b < 0:
        b += 1
  
  return flag

ans = -1
for h in range(1, H+1):
  for w in range(1, W+1):
    if edges[h][w] == "#":
      continue
    ans = max(ans, dfs(w, h))

print(ans)

Fixed submission:

H, W = map(int, input().split())
S = ["#" * (W + 2)] + ["#" + input() + "#" for _ in range(H)] + ["#" * (W + 2)]

LEFT = [[0 for j in range(W+2)] for i in range(H+2)]
RIGHT = [[0 for j in range(W+2)] for i in range(H+2)]
UP = [[0 for j in range(W+2)] for i in range(H+2)]
DOWN = [[0 for j in range(W+2)] for i in range(H+2)]

for h in range(H+2):
  for w in range(W+2):
    if S[h][w] == ".":
      LEFT[h][w] = LEFT[h][w-1] + 1
    else:
      LEFT[h][w] = 0

for h in range(H+2):
  for w in range(W+2)[::-1]:
    if S[h][w] == ".":
      RIGHT[h][w] = RIGHT[h][w+1] + 1
    else:
      RIGHT[h][w] = 0

for h in range(H+2)[::-1]:
  for w in range(W+2):
    if S[h][w] == ".":
      UP[h][w] = UP[h+1][w] + 1
    else:
      UP[h][w] = 0

for h in range(H+2):
  for w in range(W+2):
    if S[h][w] == ".":
      DOWN[h][w] = DOWN[h-1][w] + 1
    else:
      DOWN[h][w] = 0

ans = -1

for h in range(H+2):
  for w in range(W+2):
    value = RIGHT[h][w] + LEFT[h][w] + UP[h][w] + DOWN[h][w] - 3
    ans = max(ans, value)

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):

H, W = map(int, input().split())
edges = [["#" for i in range(W+2)]] + [["#"] + [None for i in range(W)] + ["#"] for j in range(H)] + [["#" for i in range(W+2)]]

for i in range(1, H+1):
  S = input()
  for j in range(1, W+1):
    edges[i][j] = S[j-1]

def dfs(x, y):
  flag = 1

  for next in [(x+1, y), (x-1, y), (x, y+1), (x, y-1)]:
    a, b = next
    while edges[b][a] == ".":
      flag += 1
      if x - a > 0:
        a -= 1
      elif x - a < 0:
        a += 1
      elif y - b > 0:
        b -= 1
      elif y - b < 0:
        b += 1
  
  return flag

ans = -1
for h in range(1, H+1):
  for w in range(1, W+1):
    if edges[h][w] == "#":
      continue
    ans = max(ans, dfs(w, h))

print(ans)

Fixed submission:

H, W = map(int, input().split())
S = ["#" * (W + 2)] + ["#" + input() + "#" for _ in range(H)] + ["#" * (W + 2)]

LEFT = [[0 for j in range(W+2)] for i in range(H+2)]
RIGHT = [[0 for j in range(W+2)] for i in range(H+2)]
UP = [[0 for j in range(W+2)] for i in range(H+2)]
DOWN = [[0 for j in range(W+2)] for i in range(H+2)]

for h in range(H+2):
  for w in range(W+2):
    if S[h][w] == ".":
      LEFT[h][w] = LEFT[h][w-1] + 1
    else:
      LEFT[h][w] = 0

for h in range(H+2):
  for w in range(W+2)[::-1]:
    if S[h][w] == ".":
      RIGHT[h][w] = RIGHT[h][w+1] + 1
    else:
      RIGHT[h][w] = 0

for h in range(H+2)[::-1]:
  for w in range(W+2):
    if S[h][w] == ".":
      UP[h][w] = UP[h+1][w] + 1
    else:
      UP[h][w] = 0

for h in range(H+2):
  for w in range(W+2):
    if S[h][w] == ".":
      DOWN[h][w] = DOWN[h-1][w] + 1
    else:
      DOWN[h][w] = 0

ans = -1

for h in range(H+2):
  for w in range(W+2):
    value = RIGHT[h][w] + LEFT[h][w] + UP[h][w] + DOWN[h][w] - 3
    ans = max(ans, value)

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):

H, W = map(int, input().split())
edges = [["#" for i in range(W+2)]] + [["#"] + [None for i in range(W)] + ["#"] for j in range(H)] + [["#" for i in range(W+2)]]

for i in range(1, H+1):
  S = input()
  for j in range(1, W+1):
    edges[i][j] = S[j-1]

def dfs(x, y):
  flag = 1

  for next in [(x+1, y), (x-1, y), (x, y+1), (x, y-1)]:
    a, b = next
    while edges[b][a] == ".":
      flag += 1
      if x - a > 0:
        a -= 1
      elif x - a < 0:
        a += 1
      elif y - b > 0:
        b -= 1
      elif y - b < 0:
        b += 1
  
  return flag

ans = -1
for h in range(1, H+1):
  for w in range(1, W+1):
    if edges[h][w] == "#":
      continue
    flag = dfs(w, h)
    ans = max(ans, dfs(w, h))

print(ans)

Fixed submission:

H, W = map(int, input().split())
S = ["#" * (W + 2)] + ["#" + input() + "#" for _ in range(H)] + ["#" * (W + 2)]

LEFT = [[0 for j in range(W+2)] for i in range(H+2)]
RIGHT = [[0 for j in range(W+2)] for i in range(H+2)]
UP = [[0 for j in range(W+2)] for i in range(H+2)]
DOWN = [[0 for j in range(W+2)] for i in range(H+2)]

for h in range(H+2):
  for w in range(W+2):
    if S[h][w] == ".":
      LEFT[h][w] = LEFT[h][w-1] + 1
    else:
      LEFT[h][w] = 0

for h in range(H+2):
  for w in range(W+2)[::-1]:
    if S[h][w] == ".":
      RIGHT[h][w] = RIGHT[h][w+1] + 1
    else:
      RIGHT[h][w] = 0

for h in range(H+2)[::-1]:
  for w in range(W+2):
    if S[h][w] == ".":
      UP[h][w] = UP[h+1][w] + 1
    else:
      UP[h][w] = 0

for h in range(H+2):
  for w in range(W+2):
    if S[h][w] == ".":
      DOWN[h][w] = DOWN[h-1][w] + 1
    else:
      DOWN[h][w] = 0

ans = -1

for h in range(H+2):
  for w in range(W+2):
    value = RIGHT[h][w] + LEFT[h][w] + UP[h][w] + DOWN[h][w] - 3
    ans = max(ans, value)

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):

H, W = map(int, input().split())
edges = [["#" for i in range(W+2)]] + [["#"] + [None for i in range(W)] + ["#"] for j in range(H)] + [["#" for i in range(W+2)]]
from collections import deque

for i in range(1, H+1):
  S = input()
  for j in range(1, W+1):
    edges[i][j] = S[j-1]

def dfs(x, y):
  if edges[y][x] == "#":
    return []

  flag = [[False for i in range(W+2)] for j in range(H+2)]
  flag[y][x] = True

  for next in [(x+1, y), (x-1, y), (x, y+1), (x, y-1)]:
    a, b = next
    while edges[b][a] == ".":
      flag[b][a] = True
      if x - a > 0:
        a -= 1
      elif x - a < 0:
        a += 1
      elif y - b > 0:
        b -= 1
      elif y - b < 0:
        b += 1
  
  return flag

ans = -1
for h in range(1, H+1):
  for w in range(1, W+1):
    flag = dfs(w, h)
    
    tmp = 0
    for x in flag:
      for y in x:
        if y:
          tmp += 1
    
    ans = max(ans, tmp)

print(ans)

Fixed submission:

H, W = map(int, input().split())
S = ["#" * (W + 2)] + ["#" + input() + "#" for _ in range(H)] + ["#" * (W + 2)]

LEFT = [[0 for j in range(W+2)] for i in range(H+2)]
RIGHT = [[0 for j in range(W+2)] for i in range(H+2)]
UP = [[0 for j in range(W+2)] for i in range(H+2)]
DOWN = [[0 for j in range(W+2)] for i in range(H+2)]

for h in range(H+2):
  for w in range(W+2):
    if S[h][w] == ".":
      LEFT[h][w] = LEFT[h][w-1] + 1
    else:
      LEFT[h][w] = 0

for h in range(H+2):
  for w in range(W+2)[::-1]:
    if S[h][w] == ".":
      RIGHT[h][w] = RIGHT[h][w+1] + 1
    else:
      RIGHT[h][w] = 0

for h in range(H+2)[::-1]:
  for w in range(W+2):
    if S[h][w] == ".":
      UP[h][w] = UP[h+1][w] + 1
    else:
      UP[h][w] = 0

for h in range(H+2):
  for w in range(W+2):
    if S[h][w] == ".":
      DOWN[h][w] = DOWN[h-1][w] + 1
    else:
      DOWN[h][w] = 0

ans = -1

for h in range(H+2):
  for w in range(W+2):
    value = RIGHT[h][w] + LEFT[h][w] + UP[h][w] + DOWN[h][w] - 3
    ans = max(ans, value)

print(ans)