Problem p03436 (python)

Fixed submission:
import sys
from collections import deque
sys.setrecursionlimit(10**8)

H, W = map(int, input().split()) 
S = [list(input()) for i in range(H)]

Kuro = 0
Shiro = 0
for j in range(H):
    for i in range(W):
        if S[j][i]=='.':
            Shiro += 1
Dis =[[-1]*W for i in range(H)]
X =[-1, 0, 1, 0]
Y =[0, -1, 0, 1]
q = deque()
q.append((0,0))
Dis[0][0] = 0
a=deque()
while (q != a):
    y,x = q.popleft()
    if (y==H-1) and (x==W-1):
        break
    for i in range(4):
        nx = x + X[i]
        ny = y + Y[i]
        if (0<= nx < W) and(0 <= ny < H) and (S[ny][nx]=='.') and (Dis[ny][nx] ==-1):
            q.append((ny,nx))
            Dis[ny][nx] = Dis[y][x] +1

if (Dis[H-1][W-1]==-1):
    print(-1)
else:
    print(Shiro-Dis[H-1][W-1]-1)

Buggy submission (verdict: Runtime Error):
import sys
from collections import deque
sys.setrecursionlimit(10**8)

H, W = map(int, input().split()) 
S = [list(input()) for i in range(H)]

Kuro = 0
Shiro = 0
for j in range(H):
    for i in range(W):
        if S[j][i]=='.':
            Shiro += 1
Dis =[[-1]*W for i in range(H)]
X =[-1, 0, 1, 0]
Y =[0, -1, 0, 1]
q = deque()
q.append((0,0))
Dis[0][0] = 0
while True:
    y,x = q.popleft()
    if (y==H-1) and (x==W-1):
        break
    for i in range(4):
        nx = x + X[i]
        ny = y + Y[i]
        if (0<= nx < W) and(0 <= ny < H) and (S[ny][nx]=='.') and (Dis[ny][nx] ==-1):
            q.append((ny,nx))
            Dis[ny][nx] = Dis[y][x] +1

print(Shiro-Dis[H-1][W-1]-1)

Buggy submission (verdict: Runtime Error):
import sys
from collections import deque
sys.setrecursionlimit(10**8)

H, W = map(int, input().split()) 
S = [list(input()) for i in range(H)]

Kuro = 0
Shiro = 0
for j in range(H):
    for i in range(W):
        if S[j][i]=='.':
            Shiro += 1
Dis =[[0]*W for i in range(H)]
X =[1, 0]
Y =[0, 1]
q = deque()
q.append((0,0))
while True:
    y,x = q.popleft()
    if (y==H-1) and (x==W-1):
        break
    for i in range(2):
        nx = x + X[i]
        ny = y + Y[i]
        if (0<= nx < W) and(0 <= ny < H) and (S[ny][nx]=='.') and(Dis[ny][nx] ==0):
            q.append((ny,nx))
            Dis[ny][nx] = Dis[y][x] +1

print(Shiro-Dis[H-1][W-1]-1)

Buggy submission (verdict: Runtime Error):
import sys
from collections import deque
sys.setrecursionlimit(10**8)

H, W = map(int, input().split()) 
S = [list(input()) for i in range(H)]

Kuro = 0
Shiro = 0
for j in range(H):
    for i in range(W):
        if S[j][i]=='.':
            Shiro += 1
Dis =[[0]*W for i in range(H)]
X =[-1, 0, 1, 0]
Y =[0, -1, 0, 1]
q = deque()
q.append((0,0))
while True:
    y,x = q.popleft()
    if (y==H-1) and (x==W-1):
        break
    for i in range(4):
        nx = x + X[i]
        ny = y + Y[i]
        if (0<= nx < W) and(0 <= ny < H) and (S[ny][nx]=='.') and(Dis[ny][nx] ==0):
            q.append((ny,nx))
            Dis[ny][nx] = Dis[y][x] +1

print(Shiro-Dis[H-1][W-1]-1)

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10**9)

from collections import deque
H, W = map(int, input().split()) 
S = [list(input()) for i in range(H)]

Kuro = 0
Shiro = 0
for j in range(H):
    for i in range(W):
        if S[j][i]=='.':
            Shiro += 1
        else:
            Kuro += 1

Dis =[[0]*W for i in range(H)]
X =[-1, 0, 1, 0]
Y =[0, -1, 0, 1]
q = deque()
q.append((0,0))
while True:
    y,x = q.popleft()
    if (y==H-1) and (x==W-1):
        break
    for i in range(4):
        nx = x + X[i]
        ny = y + Y[i]
        if (0<= nx < W) and(0 <= ny < H) and (S[ny][nx]=='.') and(Dis[ny][nx] ==0):
            q.append((ny,nx))
            Dis[ny][nx] = Dis[y][x] +1

print(Shiro-Dis[H-1][W-1]-1)

Buggy submission (verdict: Runtime Error):
from collections import deque
H, W = map(int, input().split()) 
S = [list(input()) for i in range(H)]

Kuro = 0
Shiro = 0
for j in range(H):
    for i in range(W):
        if S[j][i]=='.':
            Shiro += 1
        else:
            Kuro += 1

Dis =[[0]*W for i in range(H)]
X =[-1, 0, 1, 0]
Y =[0, -1, 0, 1]
q = deque()
q.append((0,0))
while True:
    y,x = q.popleft()
    if (y==H-1) and (x==W-1):
        break
    for i in range(4):
        nx = x + X[i]
        ny = y + Y[i]
        if (0<= nx < W) and(0 <= ny < H) and (S[ny][nx]=='.') and(Dis[ny][nx] ==0):
            q.append((ny,nx))
            Dis[ny][nx] = Dis[y][x] +1

print(Shiro-Dis[H-1][W-1]-1)

Buggy submission (verdict: Runtime Error):
from collections import deque
H, W = map(int, input().split()) 
S = [list(input()) for i in range(R)]

Kuro = 0
Shiro = 0
for j in range(H):
    for i in range(W):
        if S[j][i]=='.':
            Shiro += 1
        else:
            Kuro += 1

Dis =[[0]*W for i in range(H)]
X =[-1, 0, 1, 0]
Y =[0, -1, 0, 1]
q = deque()
q.append((0,0))
while True:
    y,x = q.popleft()
    if (y==H-1) and (x==W-1):
        break
    for i in range(4):
        nx = x + X[i]
        ny = y + Y[i]
        if (0<= nx < W) and(0 <= ny < H) and (S[ny][nx]=='.') and(Dis[ny][nx] ==0):
            q.append((ny,nx))
            Dis[ny][nx] = Dis[y][x] +1

print(Shiro-Dis[H-1][W-1]-1)

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10**9)
from collections import deque
H, W = map(int, input().split()) 
S = [list(input()) for i in range(R)]

Kuro = 0
Shiro = 0
for j in range(H):
    for i in range(W):
        if S[j][i]=='.':
            Shiro += 1
        else:
            Kuro += 1

Dis =[[0]*W for i in range(H)]
X =[-1, 0, 1, 0]
Y =[0, -1, 0, 1]
q = deque()
q.append((0,0))
while True:
    y,x = q.popleft()
    if (y==H-1) and (x==W-1):
        break
    for i in range(4):
        nx = x + X[i]
        ny = y + Y[i]
        if (0<= nx < W) and(0 <= ny < H) and (S[ny][nx]=='.') and(Dis[ny][nx] ==0):
            q.append((ny,nx))
            Dis[ny][nx] = Dis[y][x] +1

print(Shiro-Dis[H-1][W-1]-1)

Buggy submission (verdict: Runtime Error):
from collections import deque
H, W = map(int, input().split()) 
S = [list(input()) for i in range(R)]

Kuro = 0
Shiro = 0
for j in range(H):
    for i in range(W):
        if S[j][i]=='.':
            Shiro += 1
        else:
            Kuro += 1

Dis =[[0]*W for i in range(H)]
X =[-1, 0, 1, 0]
Y =[0, -1, 0, 1]
q = deque()
q.append((0,0))
while True:
    y,x = q.popleft()
    if (y==H-1) and (x==W-1):
        break
    for i in range(4):
        nx = x + X[i]
        ny = y + Y[i]
        if (0<= nx < W) and(0 <= ny < H) and (S[ny][nx]=='.') and(Dis[ny][nx] ==0):
            q.append((ny,nx))
            Dis[ny][nx] = Dis[y][x] +1

print(Shiro-Dis[H-1][W-1]-1)

Buggy submission (verdict: Runtime Error):
from collections import deque
H, W = map(int, input().split()) 
S = [list(input()) for i in range(R)]

Kuro = 0
Shiro = 0
for j in range(H):
    for i in range(W):
        if S[j][i]=='.':
            Shiro += 1
        else:
            Kuro += 1

Dis =[[0]*W for i in range(H)]
X =[-1, 0, 1, 0]
Y =[0, -1, 0, 1]
q = deque()
q.append((0,0))
while True:
    y,x = q.popleft()
    if (y==H-1) and (x==W-1):
        break
    for i in range(4):
        nx = x + X[i]
        ny = y + Y[i]
        if (0<= nx < W) and(0 <= ny < H) and (S[ny][nx]=='.') and(Dis[ny][nx] ==0):
            q.append((ny,nx))
            Dis[ny][nx] = Dis[y][x] +1

print(Shiro-Dis[H-1][W-1]-1)