Submission #4044309
Source Code Expand
from queue import Queue inf = 10 ** 20 def bfs(H, W, s): 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 | 400 |
Code Size | 877 Byte |
Status | AC |
Exec Time | 48 ms |
Memory | 4208 KB |
Judge Result
Set Name | Sample | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 400 / 400 | ||||
Status |
|
|
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 | AC | 39 ms | 4208 KB |
in02.txt | AC | 26 ms | 3952 KB |
in03.txt | AC | 26 ms | 3952 KB |
in04.txt | AC | 26 ms | 3952 KB |
in05.txt | AC | 26 ms | 3952 KB |
in06.txt | AC | 26 ms | 3952 KB |
in07.txt | AC | 26 ms | 3952 KB |
in08.txt | AC | 26 ms | 3952 KB |
in09.txt | AC | 26 ms | 3952 KB |
in10.txt | AC | 26 ms | 3952 KB |
in11.txt | AC | 27 ms | 3952 KB |
in12.txt | AC | 27 ms | 3952 KB |
in13.txt | AC | 26 ms | 3952 KB |
in14.txt | AC | 26 ms | 3952 KB |
in15.txt | AC | 44 ms | 3952 KB |
in16.txt | AC | 48 ms | 3952 KB |
in17.txt | AC | 44 ms | 3952 KB |
in18.txt | AC | 44 ms | 3952 KB |
s1.txt | AC | 26 ms | 3952 KB |
s2.txt | AC | 27 ms | 3952 KB |