-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPython.py
76 lines (52 loc) · 1.46 KB
/
Python.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# Portage du code C++ vers Python car "No More Pythons" :3
import sys
sys.setrecursionlimit(80 * 80)
dy:list = [0, 1, 0, -1]
dx:list = [1, 0, -1, 0]
dn:list = ['-', '|', '-', '|']
tail:list = ['>', 'v', '<', '^']
def dfs(map:list, y:int, x:int)->int:
curr:str = map[y][x]
map[y][x] = '.'
if(curr == 'v' or curr == '<' or curr == '>' or curr == '^'):
return 1
d:int = 0
while(d < 4):
_y:int = y + dy[d]
_x:int = x + dx[d]
if(not (_y >= 0 and _y < len(map) and _x >= 0 and _x < len(map[0]) )):
d += 1
continue
next:str = map[_y][_x]
if( (curr == '*' or curr == 'o') and next == dn[d] ):
return dfs(map, _y, _x) + 1
if(curr == dn[d] and ( next == dn[d] or next == '*' or next == 'o' or next == tail[d] )):
return dfs(map, _y, _x) + 1
d += 1
return -1
n:int
m:int
n, m = [int(i) for i in input().split()]
map:list = []
for i in range(n):
t:str = input()
line:list = []
for j in range(m):
line.append(t[j])
map.append(line)
maxSize:int = 0
count:int = 0
i:int = 0
while(i < n):
j:int = 0
while(j < m):
if(map[i][j] == 'o'):
result:int = dfs(map, i, j)
if(result > maxSize):
maxSize = result
count = 1
elif(result == maxSize):
count += 1
j += 1
i += 1
print(maxSize, '\n', count, sep="")