Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque

INF = float('inf')

dr = (-1, 0, 0, 1)
dc = (0, -1, 1, 0)

H, W = map(int, input().split())

s = []
total_white_count = 0
for _ in range(H):
    t = tuple(map(lambda x: 1 if x == '.' else 0, list(input())))
    s.append(t)
    total_white_count += sum(t)
p = [[INF for _ in range(W)] for _ in range(H)]

ans = -1

dq = deque()
dq.append((0, 0, 1))
while dq:
    r, c, d = dq.pop()

    for i in range(4):
        nr = r + dr[i]
        nc = c + dc[i]
        nd = d + 1
        if not (0 <= nr < H and 0 <= nc < W): continue
        if s[nr][nc] == 0 : continue
        if p[nr][nc] <= nd: continue
        p[nr][nc] = nd
        if nr == H - 1 and nc == W - 1:
            ans = total_white_count - nd
            break
        dq.append((nr, nc, nd))

print(ans)


Fixed submission:
from collections import deque

INF = float('inf')

dr = (-1, 0, 0, 1)
dc = (0, -1, 1, 0)

H, W = map(int, input().split())

s = []
total_white_count = 0
for _ in range(H):
    t = input()
    s.append(t)
    total_white_count += t.count('.')
p = [[INF for _ in range(W)] for _ in range(H)]

ans = -1

dq = deque()
dq.append((0, 0, 1))
while dq:
    r, c, d = dq.popleft() # 直した

    nd = d + 1
    for i in range(4):
        nr = r + dr[i]
        nc = c + dc[i]
        if not (0 <= nr < H and 0 <= nc < W): continue
        if s[nr][nc] == '#' : continue
        if p[nr][nc] <= nd: continue
        p[nr][nc] = nd
        if nr == H - 1 and nc == W - 1:
            ans = total_white_count - nd
            break
        dq.append((nr, nc, nd))
    else:
        continue
    break

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque

INF = float('inf')

dr = (-1, 0, 0, 1)
dc = (0, -1, 1, 0)

H, W = map(int, input().split())
s = [input() for _ in range(H)]
p = [[INF for _ in range(W)] for _ in range(H)]

ans = -1

dq = deque()
dq.append((0, 0, 1))
while dq:
    r, c, d = dq.pop()
    if r == H - 1 and c == W - 1:
        ans = sum(s[r].count('.') for r in range(H)) - d
        break

    for i in range(4):
        nr = r + dr[i]
        nc = c + dc[i]
        nd = d + 1
        if not (0 <= nr < H and 0 <= nc < W): continue
        if s[nr][nc] == '#': continue
        if p[nr][nc] < nd: continue
        dq.append((nr, nc, nd))

print(ans)


Fixed submission:
from collections import deque

INF = float('inf')

dr = (-1, 0, 0, 1)
dc = (0, -1, 1, 0)

H, W = map(int, input().split())

s = []
total_white_count = 0
for _ in range(H):
    t = input()
    s.append(t)
    total_white_count += t.count('.')
p = [[INF for _ in range(W)] for _ in range(H)]

ans = -1

dq = deque()
dq.append((0, 0, 1))
while dq:
    r, c, d = dq.popleft() # 直した

    nd = d + 1
    for i in range(4):
        nr = r + dr[i]
        nc = c + dc[i]
        if not (0 <= nr < H and 0 <= nc < W): continue
        if s[nr][nc] == '#' : continue
        if p[nr][nc] <= nd: continue
        p[nr][nc] = nd
        if nr == H - 1 and nc == W - 1:
            ans = total_white_count - nd
            break
        dq.append((nr, nc, nd))
    else:
        continue
    break

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque

INF = float('inf')

dr = (-1, 0, 0, 1)
dc = (0, -1, 1, 0)

H, W = map(int, input().split())
s = [input() for _ in range(H)]
p = [[INF for _ in range(W)] for _ in range(H)]

ans = -1

dq = deque()
dq.append((0, 0, 1))
while dq:
    r, c, d = dq.pop()
    if r == H - 1 and c == W - 1:
        ans = sum(s[r].count('.') for r in range(H)) - d
        break

    for i in range(4):
        nr = r + dr[i]
        nc = c + dc[i]
        nd = d + 1
        if not (0 <= nr < H and 0 <= nc < W): continue
        if s[nr][nc] == '#': continue
        if p[nr][nc] < nd: continue
        dq.append((nr, nc, nd))

print(ans)


Fixed submission:
from collections import deque

INF = float('inf')

dr = (-1, 0, 0, 1)
dc = (0, -1, 1, 0)

H, W = map(int, input().split())

s = []
total_white_count = 0
for _ in range(H):
    t = input()
    s.append(t)
    total_white_count += t.count('.')
p = [[INF for _ in range(W)] for _ in range(H)]

ans = -1

dq = deque()
dq.append((0, 0, 1))
while dq:
    r, c, d = dq.popleft() # 直した

    nd = d + 1
    for i in range(4):
        nr = r + dr[i]
        nc = c + dc[i]
        if not (0 <= nr < H and 0 <= nc < W): continue
        if s[nr][nc] == '#' : continue
        if p[nr][nc] <= nd: continue
        p[nr][nc] = nd
        if nr == H - 1 and nc == W - 1:
            ans = total_white_count - nd
            break
        dq.append((nr, nc, nd))
    else:
        continue
    break

print(ans)