-
Notifications
You must be signed in to change notification settings - Fork 0
/
day70.py
85 lines (69 loc) · 2.91 KB
/
day70.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
#!/bin/python3
import sys
import copy
class ValidPlus:
def __init__(self):
self.area = 1
self.length = 1
self.cells = []
def addCell(self, cell):
self.cells.append(cell)
class Cell:
def __init__(self, row, column):
self.row = row
self.column = column
def __str__(self):
return str(self.row) + str(self.column)
def __hash__(self):
return hash(str(self))
def __eq__(self, other):
return self.row == other.row and self.column == other.column
def __gt__(self, other):
return self.row > other.row and self.column > other.column
def __lt__(self, other):
return self.row < other.row and self.column < other.column
if __name__ == '__main__':
n, m = input().strip().split(' ')
n, m = [int(n), int(m)]
grid = []
grid_i = 0
for grid_i in range(n):
grid_t = str(input().strip())
grid.append(grid_t)
validPluses = []
for i in range(n):
for j in range(m):
current_cell = grid[i][j]
if current_cell == 'G':
there_is_a_good_cell = True
validPlus = ValidPlus()
length = 1
validPlus.addCell(Cell(i,j))
validPluses.append(validPlus)
while there_is_a_good_cell:
if (i - length >= 0 and grid[i - length][j] == 'G') and (i + length < n and grid[i + length][j] == 'G') and (j - length >= 0 and grid[i][j - length] == 'G') and (j + length < m and grid[i][j + length] == 'G'):
new_valid_plus = copy.deepcopy(validPlus)
new_valid_plus.addCell(Cell(i - length, j))
new_valid_plus.addCell(Cell(i + length, j))
new_valid_plus.addCell(Cell(i, j - length))
new_valid_plus.addCell(Cell(i, j + length))
length += 1
new_valid_plus.area = 1 + (4 * (length - 1))
new_valid_plus.length = length
validPluses.append(new_valid_plus)
validPlus = copy.deepcopy(new_valid_plus)
else:
there_is_a_good_cell = False
max_area = 0
for i in range(len(validPluses)):
current_valid_plus = validPluses[i]
for j in range(i + 1, len(validPluses)):
other_valid_plus = validPluses[j]
current_area = current_valid_plus.area * other_valid_plus.area
if current_area > max_area:
current_cells = current_valid_plus.cells
other_cells = other_valid_plus.cells
common_cells = set(current_cells) - (set(current_cells) - set(other_cells))
if len(common_cells) == 0:
max_area = current_area
print(max_area)