Submission #54864773
Source Code Expand
import networkx as nx
H, W = map(int, input().split())
maze = [input() for _ in range(H)]
G = nx.Graph()
# 辺を加えていく
for h in range(H):
for w in range(W - 1):
if maze[h][w] == maze[h][w + 1] == '.':
G.add_edge((h, w), (h, w + 1))
for h in range(H - 1):
for w in range(W):
if maze[h][w] == maze[h + 1][w] == '.':
G.add_edge((h, w), (h + 1, w))
def bfs(sy, sx):
d = dict()
d[(sy, sx)] = 0
for coordinate_from, coordinate_to in nx.bfs_edges(G, (sy, sx)):
d[coordinate_to] = d[coordinate_from] + 1
return max(d.values())
ans = 0
for y in range(H):
for x in range(W):
if maze[y][x] == '.':
ans = max(ans, bfs(y, x))
print(ans)
Submission Info
| Submission Time | |
|---|---|
| Task | D - Maze Master |
| User | H3PO4 |
| Language | Python (CPython 3.11.4) |
| Score | 400 |
| Code Size | 767 Byte |
| Status | AC |
| Exec Time | 293 ms |
| Memory | 29356 KiB |
Judge Result
| Set Name | Sample | All | ||||
|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 400 / 400 | ||||
| Status |
|
|
| Set Name | Test Cases |
|---|---|
| Sample | sample_01, sample_02 |
| All | hand_01, hand_02, hand_03, hand_04, hand_05, hand_06, hand_07, hand_08, hand_09, hand_10, sample_01, sample_02, small_01, small_02, small_03, small_04 |
| Case Name | Status | Exec Time | Memory |
|---|---|---|---|
| hand_01 | AC | 148 ms | 28944 KiB |
| hand_02 | AC | 111 ms | 28856 KiB |
| hand_03 | AC | 112 ms | 28876 KiB |
| hand_04 | AC | 133 ms | 28900 KiB |
| hand_05 | AC | 167 ms | 29124 KiB |
| hand_06 | AC | 163 ms | 28828 KiB |
| hand_07 | AC | 125 ms | 28764 KiB |
| hand_08 | AC | 293 ms | 29356 KiB |
| hand_09 | AC | 108 ms | 28852 KiB |
| hand_10 | AC | 115 ms | 29064 KiB |
| sample_01 | AC | 105 ms | 28940 KiB |
| sample_02 | AC | 107 ms | 28752 KiB |
| small_01 | AC | 106 ms | 28792 KiB |
| small_02 | AC | 107 ms | 28824 KiB |
| small_03 | AC | 150 ms | 28740 KiB |
| small_04 | AC | 106 ms | 28788 KiB |