-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEHelpCaretaker.py
92 lines (80 loc) · 2.41 KB
/
EHelpCaretaker.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
def to_tuple(lst):
return tuple(to_tuple(i) if isinstance(i, list) else i for i in lst)
def process(r,c,R,C,S,B,countT):
if r==3 and c==3:
print()
global ans
ans = max(ans,countT)
if to_tuple(B) in S:
return
S.add(to_tuple(B))
if (R-r<3 or C-c<3):
ans = max(ans,countT)
return
if B[r][c] == '.' and B[r][c+1] == '.' and B[r][c+2] == '.' and B[r+1][c+1] == '.' and B[r+2][c+1] == '.':
B[r][c] = '#'
B[r][c+1] = '#'
B[r][c+2] = '#'
B[r+1][c+1] = '#'
B[r+2][c+1] = '#'
if c+3>=C:
process(r+1,0,R,C,S,B,countT+1)
else:
process(r,c+1,R,C,S,B,countT+1)
B[r][c] = '.'
B[r][c+1] = '.'
B[r][c+2] = '.'
B[r+1][c+1] = '.'
B[r+2][c+1] = '.'
if B[r+1][c] == '.' and B[r+1][c+1] == '.' and B[r+1][c+2] == '.' and B[r][c+2] == '.' and B[r+2][c+2] == '.':
B[r+1][c] = '#'
B[r+1][c+1] = '#'
B[r+1][c+2] = '#'
B[r][c+2] = '#'
B[r+2][c+2] = '#'
if c+3>=C:
process(r+1,0,R,C,S,B,countT+1)
else:
process(r,c+1,R,C,S,B,countT+1)
B[r+1][c] = '.'
B[r+1][c+1] = '.'
B[r+1][c+2] = '.'
B[r][c+2] = '.'
B[r+2][c+2] = '.'
if B[r+2][c] == '.' and B[r+2][c+1] == '.' and B[r+2][c+2] == '.' and B[r][c+1] == '.' and B[r+1][c+1] == '.':
B[r+2][c] = '#'
B[r+2][c+1] = '#'
B[r+2][c+2] = '#'
B[r][c+1] = '#'
B[r+1][c+1] = '#'
if c+3>=C:
process(r+1,0,R,C,S,B,countT+1)
else:
process(r,c+1,R,C,S,B,countT+1)
B[r+2][c] = '.'
B[r+2][c+1] = '.'
B[r+2][c+2] = '.'
B[r][c+1] = '.'
B[r+1][c+1] = '.'
if B[r][c] == '.' and B[r+1][c] == '.' and B[r+2][c] == '.' and B[r+1][c+1] == '.' and B[r+1][c+2] == '.':
B[r][c] = '#'
B[r+1][c] = '#'
B[r+2][c] = '#'
B[r+1][c+1] = '#'
B[r+1][c+2] = '#'
if c+3>=C:
process(r+1,0,R,C,S,B,countT+1)
else:
process(r,c+1,R,C,S,B,countT+1)
B[r][c] = '.'
B[r+1][c] = '.'
B[r+2][c] = '.'
B[r+1][c+1] = '.'
B[r+1][c+2] = '.'
R,C = [int(i) for i in input().split()]
ans = 0
S = set()
B = [ ["."]*C for i in range(R) ]
process(0,0,R,C,S,B,0)
print(ans)
print(S)