Problem p03014 (python)

Fixed submission:
h, w = map(int, input().split())
s = [list(input()) 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):
    if s[i][0] == '.':
        L[i][0] = 1
    for j in range(1, w):
        if s[i][j] == '.':
            L[i][j] = L[i][j-1] + 1
    if s[i][w-1] == '.':
        R[i][w-1] = 1
    for j in range(w-2, -1, -1):
        if s[i][j] == '.':
            R[i][j] = R[i][j+1] + 1

for j in range(w):
    if s[0][j] == '.':
        U[0][j] = 1
    for i in range(1, h):
        if s[i][j] == '.':
            U[i][j] = U[i-1][j] + 1
    if s[h-1][j] == '.':
        D[h-1][j] = 1
    for i in range(h-2, -1, -1):
        if s[i][j] == '.':
            D[i][j] = D[i+1][j] + 1

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

print(ans)

Buggy submission (verdict: Runtime Error):
h, w = map(int, input().split())
s = [list(input()) for _ in range(h)]

if h == 1 and w == 1:
    print(s[100000][100000])
    if s[0][0] == '.':
        print(1)
    else:
        print(0)
    exit()
elif h == 1:
    a = [0] * w
    mode = 0
    for i in range(w):
        if mode == 0:
            if s[0][i] == '.':
                c = 1
                a[i] = c
                mode = 1
        else:
            if s[0][i] == '.':
                c += 1
                a[i] = c
            else:
                mode = 0
    print(max(a))
    exit()
elif w == 1:
    b = [0] * h
    mode = 0
    for i in range(h):
        if mode == 0:
            if s[i][0] == '.':
                c = 1
                b[i] = c
                mode = 1
        else:
            if s[i][0] == '.':
                c += 1
                b[i] = c
            else:
                mode = 0
    print(max(b))
    exit()

exit()

a = [[0 for _ in range(w)] for _ in range(h)]
b = [[0 for _ in range(w)] for _ in range(h)]

c = 0

for i in range(h):
    mode = 0
    for j in range(w):
        if mode == 0:
            if s[i][j] == '.':
                c = 1
                a[i][j] = 1
                mode = 1
        else:
            if s[i][j] == '.':
                c += 1
                a[i][j] = c
            else:
                mode = 0

    for j in range(w-2, -1, -1):
        if a[i][j+1] > 0 and a[i][j] > 0:
            a[i][j] = a[i][j+1]

ans = 0

for j in range(w):
    mode = 0
    for i in range(h):
        if mode == 0:
            if s[i][j] == '.':
                c = 1
                b[i][j] = c
                mode = 1
        else:
            if s[i][j] == '.':
                c += 1
                b[i][j] = c
            else:
                mode = 0

    #print(b)

    for i in range(h-2, -1, -1):
        if b[i+1][j] > 0 and b[i][j] > 0:
            b[i][j] = b[i+1][j]
            ans = max(ans, a[i][j] + b[i][j] - 1)
        elif b[i][j] > 0:
            ans = max(ans, a[i][j] + b[i][j] - 1)

print(ans)

Buggy submission (verdict: Runtime Error):
h, w = map(int, input().split())
s = [list(input()) for _ in range(h)]

if h == 1 and w == 1:
    if s[0][0] == '.':
        print(1)
    else:
        print(0)
    exit()
elif h == 1:
    print(s[100000][1000000])
    a = [0] * w
    mode = 0
    for i in range(w):
        if mode == 0:
            if s[0][i] == '.':
                c = 1
                a[i] = c
                mode = 1
        else:
            if s[0][i] == '.':
                c += 1
                a[i] = c
            else:
                mode = 0
    print(max(a))
    exit()
elif w == 1:
    b = [0] * h
    mode = 0
    for i in range(h):
        if mode == 0:
            if s[i][0] == '.':
                c = 1
                b[i] = c
                mode = 1
        else:
            if s[i][0] == '.':
                c += 1
                b[i] = c
            else:
                mode = 0
    print(max(b))
    exit()

exit()

a = [[0 for _ in range(w)] for _ in range(h)]
b = [[0 for _ in range(w)] for _ in range(h)]

c = 0

for i in range(h):
    mode = 0
    for j in range(w):
        if mode == 0:
            if s[i][j] == '.':
                c = 1
                a[i][j] = 1
                mode = 1
        else:
            if s[i][j] == '.':
                c += 1
                a[i][j] = c
            else:
                mode = 0

    for j in range(w-2, -1, -1):
        if a[i][j+1] > 0 and a[i][j] > 0:
            a[i][j] = a[i][j+1]

ans = 0

for j in range(w):
    mode = 0
    for i in range(h):
        if mode == 0:
            if s[i][j] == '.':
                c = 1
                b[i][j] = c
                mode = 1
        else:
            if s[i][j] == '.':
                c += 1
                b[i][j] = c
            else:
                mode = 0

    #print(b)

    for i in range(h-2, -1, -1):
        if b[i+1][j] > 0 and b[i][j] > 0:
            b[i][j] = b[i+1][j]
            ans = max(ans, a[i][j] + b[i][j] - 1)
        elif b[i][j] > 0:
            ans = max(ans, a[i][j] + b[i][j] - 1)

print(ans)

Buggy submission (verdict: Runtime Error):
h, w = map(int, input().split())
s = [list(input()) for _ in range(h)]

if h == 1 and w == 1:
    if s[0][0] == '.':
        print(1)
    else:
        print(0)
    exit()
elif h == 1:
    a = [0] * w
    mode = 0
    for i in range(w):
        if mode == 0:
            if s[0][i] == '.':
                c = 1
                a[i] = c
                mode = 1
        else:
            if s[0][i] == '.':
                c += 1
                a[i] = c
            else:
                mode = 0
    print(max(a))
    exit()
elif w == 1:
    print(s[100000][1000000])
    b = [0] * h
    mode = 0
    for i in range(h):
        if mode == 0:
            if s[i][0] == '.':
                c = 1
                b[i] = c
                mode = 1
        else:
            if s[i][0] == '.':
                c += 1
                b[i] = c
            else:
                mode = 0
    print(max(b))
    exit()

exit()

a = [[0 for _ in range(w)] for _ in range(h)]
b = [[0 for _ in range(w)] for _ in range(h)]

c = 0

for i in range(h):
    mode = 0
    for j in range(w):
        if mode == 0:
            if s[i][j] == '.':
                c = 1
                a[i][j] = 1
                mode = 1
        else:
            if s[i][j] == '.':
                c += 1
                a[i][j] = c
            else:
                mode = 0

    for j in range(w-2, -1, -1):
        if a[i][j+1] > 0 and a[i][j] > 0:
            a[i][j] = a[i][j+1]

ans = 0

for j in range(w):
    mode = 0
    for i in range(h):
        if mode == 0:
            if s[i][j] == '.':
                c = 1
                b[i][j] = c
                mode = 1
        else:
            if s[i][j] == '.':
                c += 1
                b[i][j] = c
            else:
                mode = 0

    #print(b)

    for i in range(h-2, -1, -1):
        if b[i+1][j] > 0 and b[i][j] > 0:
            b[i][j] = b[i+1][j]
            ans = max(ans, a[i][j] + b[i][j] - 1)
        elif b[i][j] > 0:
            ans = max(ans, a[i][j] + b[i][j] - 1)

print(ans)