Problem p03014 (python)

Fixed submission:
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)

Buggy submission (verdict: Runtime Error):
from collections import deque
f = open("/Users/naoki/Documents/Atcoder/input.txt")

H,W = map(int,f.readline().split())
Ss = [str(f.readline()) 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)

Buggy submission (verdict: Runtime Error):
from collections import deque
f = open("/Users/naoki/Documents/Atcoder/input.txt")

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

directions = [[-1,0],
              [0,-1],
              [1,0],
              [0,1]]

answer = 0
import copy
for i in range(H):
    for j in range(W):
        if Ss[i][j]==".":
            todo = deque([[i,j]])
        else:
            continue
        candidate = 0
        while len(todo) > 0:
            base = todo.pop()
            candidate += 1
            
            for direction in directions:
                checking = copy.deepcopy(base)
                for k in range(max(H,W)):
                    checking = [checking[0]+direction[0],checking[1]+direction[1]]
                    if checking[0] < 0 or checking[0] >= H or checking[1] < 0 or checking[1] >= W:
                        break
                    if Ss[checking[0]][checking[1]] == "#":
                        break
                    candidate += 1
        if candidate > answer:
            answer = candidate
print(answer)