@@ 127-145 (lines=19) @@ | ||
124 | return answer |
|
125 | ||
126 | ||
127 | def diagonal_reverse(grid: List[List[int]], run_len: int) -> int: |
|
128 | """ Find the maximal `run_len` long product in the 'reverse' diagonal direction |
|
129 | ||
130 | The 'reverse' diagonal is defined as bottom-left to top-right when viewed in the C-array style convention. |
|
131 | ||
132 | :param grid: the two-dimensional integer grid |
|
133 | :param run_len: the product run-length |
|
134 | :return: the maximum `run_len` long product in the reverse diagonal direction from `grid` |
|
135 | """ |
|
136 | ||
137 | answer = 0 |
|
138 | n, m = len(grid), len(grid[0]) |
|
139 | for i in range(run_len - 1, n): |
|
140 | for j in range(m - run_len+1): |
|
141 | product = 1 |
|
142 | for k in range(run_len): |
|
143 | product *= grid[i-k][j+k] |
|
144 | answer = max(answer, product) |
|
145 | return answer |
|
146 | ||
147 | ||
148 | def solve(): |
|
@@ 106-124 (lines=19) @@ | ||
103 | return answer |
|
104 | ||
105 | ||
106 | def diagonal_natural(grid: List[List[int]], run_len: int) -> int: |
|
107 | """ Find the maximal `run_len` long product in the 'natural' diagonal direction |
|
108 | ||
109 | The 'natural' diagonal is defined as top-left to bottom-right when viewed in the C-array style convention. |
|
110 | ||
111 | :param grid: the two-dimensional integer grid |
|
112 | :param run_len: the product run-length |
|
113 | :return: the maximum `run_len` long product in the natural diagonal direction from `grid` |
|
114 | """ |
|
115 | ||
116 | answer = 0 |
|
117 | n, m = len(grid), len(grid[0]) |
|
118 | for i in range(n - run_len+1): |
|
119 | for j in range(m - run_len+1): |
|
120 | product = 1 |
|
121 | for k in range(run_len): |
|
122 | product *= grid[i+k][j+k] |
|
123 | answer = max(answer, product) |
|
124 | return answer |
|
125 | ||
126 | ||
127 | def diagonal_reverse(grid: List[List[int]], run_len: int) -> int: |
|
@@ 87-103 (lines=17) @@ | ||
84 | return answer |
|
85 | ||
86 | ||
87 | def vertical(grid: List[List[int]], run_len: int) -> int: |
|
88 | """ Find the maximal `run_len` long product in the vertical direction |
|
89 | ||
90 | :param grid: the two-dimensional integer grid |
|
91 | :param run_len: the product run-length |
|
92 | :return: the maximum `run_len` long product in the vertical direction from `grid` |
|
93 | """ |
|
94 | ||
95 | answer = 0 |
|
96 | n, m = len(grid), len(grid[0]) |
|
97 | for i in range(n - run_len + 1): |
|
98 | for j in range(m): |
|
99 | product = 1 |
|
100 | for k in range(run_len): |
|
101 | product *= grid[i+k][j] |
|
102 | answer = max(answer, product) |
|
103 | return answer |
|
104 | ||
105 | ||
106 | def diagonal_natural(grid: List[List[int]], run_len: int) -> int: |