Submission #4044300


Source Code Expand

from queue import Queue

def bfs(H, W, s):
    inf = 10 ** 20
    d = [[inf for i in range(W)] for j in range(H)]
    q = Queue()

    d[0][0] = 1
    q.put([0, 0])

    dx = (0, -1, 1, 0)
    dy = (-1, 0, 0, 1)

    while not q.empty():
        p = q.get()
        x = p[0]
        y = p[1]
        for i in range(4):
            nx = x + dx[i]
            ny = y + dy[i]
            if(nx >= 0 and nx < H and ny >= 0 and ny < W):
                if(s[nx][ny] == '.' and d[x][y] + 1 < d[nx][ny]):
                    d[nx][ny] = d[x][y] + 1
                    q.put([nx, ny])

    return d[H-1][W-1]

H, W = map(int, input().split())
s = []
wnum = 0
for i in range(H):
    s.append(input())
    for j in range(W):
        if(s[i][j] == "."):
            wnum += 1
d = bfs(H, W, s)
if(d == INF):
    print("-1")
else:
    print(wnum - d)

Submission Info

Submission Time
Task D - Grid Repainting
User ochikei
Language Python (3.4.3)
Score 0
Code Size 879 Byte
Status RE
Exec Time 48 ms
Memory 4208 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 400
Status
RE × 2
RE × 20
Set Name Test Cases
Sample s1.txt, s2.txt
All in01.txt, in02.txt, in03.txt, in04.txt, in05.txt, in06.txt, in07.txt, in08.txt, in09.txt, in10.txt, in11.txt, in12.txt, in13.txt, in14.txt, in15.txt, in16.txt, in17.txt, in18.txt, s1.txt, s2.txt
Case Name Status Exec Time Memory
in01.txt RE 37 ms 4208 KB
in02.txt RE 26 ms 3952 KB
in03.txt RE 26 ms 3952 KB
in04.txt RE 26 ms 3952 KB
in05.txt RE 26 ms 3952 KB
in06.txt RE 26 ms 3952 KB
in07.txt RE 26 ms 3952 KB
in08.txt RE 26 ms 3952 KB
in09.txt RE 26 ms 3952 KB
in10.txt RE 26 ms 3952 KB
in11.txt RE 27 ms 3952 KB
in12.txt RE 26 ms 3952 KB
in13.txt RE 26 ms 3952 KB
in14.txt RE 26 ms 3952 KB
in15.txt RE 44 ms 3952 KB
in16.txt RE 48 ms 3952 KB
in17.txt RE 43 ms 3952 KB
in18.txt RE 44 ms 3952 KB
s1.txt RE 26 ms 3952 KB
s2.txt RE 28 ms 3952 KB