Skip to content

Commit 5427800

Browse files
committed
Runtime: 2256 ms (Top 53.49%) | Memory: 63.7 MB (Top 23.26%)
1 parent 5bb8648 commit 5427800

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

scripts/algorithms/M/Maximize Grid Happiness/Maximize Grid Happiness.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// Runtime: 2256 ms (Top 53.49%) | Memory: 63.7 MB (Top 23.26%)
12
from functools import lru_cache
23
class Solution:
34
def getMaxGridHappiness(self, m: int, n: int, introvertsCount: int, extrovertsCount: int) -> int:
@@ -18,7 +19,7 @@ def calc(x, y): #calculate interaction
1819
ternary.append(tmp % 3)
1920
tmp //= 3
2021
mask_all[mask] = ternary[::-1]
21-
rolling[mask] = [ #get the three states after a slide
22+
rolling[mask] = [ #get the three states after a slide
2223
mask % highest * 3 + 0,
2324
mask % highest * 3 + 1,
2425
mask % highest * 3 + 2
@@ -30,12 +31,12 @@ def dfs(pos, borderline, i, e):
3031
x, y = divmod(pos, n)
3132
#put 0 in pos
3233
best = dfs(pos + 1, rolling[borderline][0], i, e)
33-
#put 1 in pos
34+
#put 1 in pos
3435
if i > 0:
3536
best = max(best, 120 + calc(1, mask_all[borderline][0]) +
3637
(0 if y == 0 else calc(1, mask_all[borderline][n - 1])) +
3738
dfs(pos + 1, rolling[borderline][1], i - 1, e))
38-
#put 2 in pos
39+
#put 2 in pos
3940
if e > 0:
4041
best = max(best, 40 + calc(2, mask_all[borderline][0]) +
4142
(0 if y == 0 else calc(2, mask_all[borderline][n - 1])) +

0 commit comments

Comments
 (0)