Submission #26404212
Source Code Expand
import copy
ans = 0
def rec(w, h, m, l: int, flags: list, start: tuple, p: tuple):
global ans
flags[p[0] * w + p[1]] = True
# print(p, l)
for (y, x) in [(0, -1), (0, 1), (-1, 0), (1, 0)]:
nex = (p[0] + y, p[1] + x)
if 0 <= nex[0] < h and 0 <= nex[1] < w and m[nex[0]][nex[1]] == ".":
# 特例
if l > 1 and nex[0] == start[0] and nex[1] == start[1]:
ans = max(ans, l + 1)
return
if not flags[nex[0] * w + nex[1]]:
new_flags = copy.copy(flags)
new_flags[nex[0] * w + nex[1]] = True
rec(w, h, m, l + 1, new_flags, start, nex)
if __name__ == "__main__":
h, w = list(map(int, input().split()))
m = []
for i in range(h):
m.append(list(input()))
for i in range(h):
for j in range(w):
flags = [False] * (w * h)
s = [i, j]
if m[s[0]][s[1]] == ".":
rec(w, h, m, 0, flags, s, s)
print(-1 if ans == 0 else ans)
Submission Info
Judge Result
| Set Name |
Sample |
All |
| Score / Max Score |
0 / 0 |
4 / 4 |
| Status |
|
|
| Set Name |
Test Cases |
| Sample |
01_sample_01.txt, 01_sample_02.txt, 01_sample_03.txt |
| All |
01_sample_01.txt, 01_sample_02.txt, 01_sample_03.txt, 02_forest_01.txt, 02_forest_02.txt, 02_forest_03.txt, 02_forest_04.txt, 02_forest_05.txt, 02_forest_06.txt, 02_forest_07.txt, 02_forest_08.txt, 02_forest_09.txt, 02_forest_10.txt, 03_white_01.txt, 03_white_02.txt, 03_white_03.txt, 03_white_04.txt, 03_white_05.txt, 04_mixed_01.txt, 04_mixed_02.txt, 04_mixed_03.txt, 04_mixed_04.txt, 04_mixed_05.txt, 04_mixed_06.txt, 04_mixed_07.txt, 04_mixed_08.txt, 04_mixed_09.txt, 04_mixed_10.txt |
| Case Name |
Status |
Exec Time |
Memory |
| 01_sample_01.txt |
AC |
221 ms |
68072 KiB |
| 01_sample_02.txt |
AC |
66 ms |
67752 KiB |
| 01_sample_03.txt |
AC |
111 ms |
75728 KiB |
| 02_forest_01.txt |
AC |
66 ms |
68012 KiB |
| 02_forest_02.txt |
AC |
65 ms |
67784 KiB |
| 02_forest_03.txt |
AC |
68 ms |
68452 KiB |
| 02_forest_04.txt |
AC |
65 ms |
68496 KiB |
| 02_forest_05.txt |
AC |
63 ms |
68092 KiB |
| 02_forest_06.txt |
AC |
68 ms |
68256 KiB |
| 02_forest_07.txt |
AC |
65 ms |
68352 KiB |
| 02_forest_08.txt |
AC |
64 ms |
68100 KiB |
| 02_forest_09.txt |
AC |
68 ms |
68764 KiB |
| 02_forest_10.txt |
AC |
65 ms |
67988 KiB |
| 03_white_01.txt |
AC |
66 ms |
68016 KiB |
| 03_white_02.txt |
AC |
99 ms |
75128 KiB |
| 03_white_03.txt |
AC |
96 ms |
74684 KiB |
| 03_white_04.txt |
AC |
159 ms |
77884 KiB |
| 03_white_05.txt |
AC |
175 ms |
76496 KiB |
| 04_mixed_01.txt |
AC |
90 ms |
74180 KiB |
| 04_mixed_02.txt |
AC |
92 ms |
74036 KiB |
| 04_mixed_03.txt |
AC |
103 ms |
75864 KiB |
| 04_mixed_04.txt |
AC |
96 ms |
74412 KiB |
| 04_mixed_05.txt |
AC |
135 ms |
76024 KiB |
| 04_mixed_06.txt |
AC |
106 ms |
75416 KiB |
| 04_mixed_07.txt |
AC |
111 ms |
75144 KiB |
| 04_mixed_08.txt |
AC |
65 ms |
69088 KiB |
| 04_mixed_09.txt |
AC |
62 ms |
68304 KiB |
| 04_mixed_10.txt |
AC |
94 ms |
74204 KiB |