Problem p03014 (python)

Fixed submission:
h, w = map(int, input().split())
grid = []
for i in range(h):
  gridi = input()
  grid.append(gridi)
xcnt = [[0]*w for i in range(h)]
ycnt = [[0]*w for i in range(h)]
ans = -10**9
# print(grid, h, w)
for y in range(h):
  cnt = 0
  for x in range(w-1):
    if grid[y][x] == "#":
      cnt = 0
      continue
    if grid[y][x+1] == "#":
      xcnt[y][x] = cnt + 1
      cnt = 0
    else:
      cnt += 1
  if grid[y][w-1] == ".":
    xcnt[y][w-1] = cnt + 1
# print(xcnt)
for y in range(h):
  for x in range(w-1):
    if grid[y][w-1-x] == "#":
      continue
    if grid[y][w-1-x-1] == ".":
      xcnt[y][w-1-x-1] = xcnt[y][w-1-x]
# print(*xcnt)

for x in range(w):
  cnt = 0
  for y in range(h-1):
    if grid[y][x] == "#":
      cnt = 0
      continue
    if grid[y+1][x] == "#":
      ycnt[y][x] = cnt + 1
      cnt = 0
    else:
      cnt += 1
  if grid[h-1][x] == ".":
    ycnt[h-1][x] = cnt + 1
# print(ycnt)
for x in range(w):
  for y in range(h-1):
    if grid[h-1-y][x] == "#":
      continue
    if grid[h-1-y-1][x] == ".":
      ycnt[h-1-y-1][x] = ycnt[h-1-y][x]
# print(*ycnt)
for y in range(h):
  for x in range(w):
    ans = max(ans, xcnt[y][x] + ycnt[y][x] - 1)
print(ans)

Buggy submission (verdict: Runtime Error):
h, w = map(int, input().split())
grid = []
for i in range(h):
  gridi = input()
  grid.append(gridi)
xcnt = [[0]*w for i in range(h)]
ycnt = [[0]*w for i in range(h)]
ans = -10**9
# print(grid, h, w)
for y in range(h):
  cnt = 0
  for x in range(w-1):
    if grid[y][x] == "#":
      cnt = 0
      continue
    if grid[y][x+1] == "#":
      xcnt[y][x] = cnt + 1
      cnt = 0
    else:
      cnt += 1
  if grid[y][x+1] == ".":
    xcnt[y][x+1] = cnt + 1
# print(xcnt)
for y in range(h):
  for x in range(w-1):
    if grid[y][w-1-x] == "#":
      continue
    if grid[y][w-1-x-1] == ".":
      xcnt[y][w-1-x-1] = xcnt[y][w-1-x]
# print(*xcnt)

for x in range(w):
  cnt = 0
  for y in range(h-1):
    if grid[y][x] == "#":
      cnt = 0
      continue
    if grid[y+1][x] == "#":
      ycnt[y][x] = cnt + 1
      cnt = 0
    else:
      cnt += 1
  if grid[y+1][x] == ".":
    ycnt[y+1][x] = cnt + 1
# print(ycnt)
for x in range(w):
  for y in range(h-1):
    if grid[h-1-y][x] == "#":
      continue
    if grid[h-1-y-1][x] == ".":
      ycnt[h-1-y-1][x] = ycnt[h-1-y][x]
# print(*ycnt)
for y in range(h):
  for x in range(w):
    ans = max(ans, xcnt[y][x] + ycnt[y][x] - 1)
print(ans)

Buggy submission (verdict: Runtime Error):
h, w = map(int, input().split())
grid = []
for i in range(h):
  gridi = input()
  grid.append(gridi)
xcnt = [[0]*w for i in range(h)]
ycnt = [[0]*w for i in range(h)]
ans = -10**9
# print(grid, h, w)
for y in range(h):
  cnt = 0
  for x in range(w-1):
    if grid[y][x] == "#":
      cnt = 0
      continue
    if grid[y][x+1] == "#":
      xcnt[y][x] = cnt + 1
      cnt = 0
    else:
      cnt += 1
  if grid[y][x+1] == ".":
    xcnt[y][x+1] = cnt + 1
# print(xcnt)
for y in range(h):
  for x in range(w-1):
    if grid[y][w-1-x] == "#":
      continue
    if grid[y][w-1-x-1] == ".":
      xcnt[y][w-1-x-1] = xcnt[y][w-1-x]
# print(*xcnt)

for x in range(w):
  cnt = 0
  for y in range(h-1):
    if grid[y][x] == "#":
      cnt = 0
      continue
    if grid[y+1][x] == "#":
      ycnt[y][x] = cnt + 1
      cnt = 0
    else:
      cnt += 1
  if grid[y+1][x] == ".":
    ycnt[y+1][x] = cnt + 1
# print(ycnt)
for x in range(w):
  for y in range(h-1):
    if grid[h-1-y][x] == "#":
      continue
    if grid[h-1-y-1][x] == ".":
      ycnt[h-1-y-1][x] = ycnt[h-1-y][x]
# print(*ycnt)
for y in range(h):
  for x in range(w):
    ans = max(ans, xcnt[y][x] + ycnt[y][x] - 1)
print(ans)