Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
kamyu104 committed Dec 19, 2023
1 parent 5cb512f commit 4b768b9
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
6 changes: 3 additions & 3 deletions Final Round/programming_paths_part_2.py3
Original file line number Diff line number Diff line change
Expand Up @@ -83,19 +83,19 @@ def precompute():
dp = {(0, 0):None}
dp2 = {0:(0, 0)}
d = 1
lookup = {(0, 0, d)}
q = [(0, 0)]
while q:
if not depths[d]:
break
lookup = set()
new_q = []
for A, B in q:
for p in range(min(len(depths[d]), 2)+1):
new_A, new_B = op(A, B, d%2, p%2) if p != 0 else (A, B)
new_d = d+1
if not (0 <= new_A <= MAX_K and 0 <= new_B <= MAX_K and (new_A, new_B, new_d) not in lookup):
if not (0 <= new_A <= MAX_K and 0 <= new_B <= MAX_K and (new_A, new_B) not in lookup):
continue
lookup.add((new_A, new_B, new_d))
lookup.add((new_A, new_B))
new_q.append((new_A, new_B))
if (new_A, new_B) not in dp:
dp[new_A, new_B] = (depths[d][:p], (A, B))
Expand Down
6 changes: 3 additions & 3 deletions Final Round/programming_paths_part_2_2.py3
Original file line number Diff line number Diff line change
Expand Up @@ -83,25 +83,25 @@ def precompute():
dp = {(0, 0):None}
dp2 = {0:(0, 0)}
d = 1
lookup = {(0, 0, d)}
q = [(0, 0)]
while q:
if not depths[d]:
break
lookup = set()
new_q = []
for A, B in q:
for p in range(min(len(depths[d]), 2)+1):
new_A, new_B = op(A, B, d%2, p%2) if p != 0 else (A, B)
new_d = d+1
if not (0 <= new_A <= MAX_K and 0 <= new_B <= MAX_K and (new_A, new_B, new_d) not in lookup):
if not (0 <= new_A <= MAX_K and 0 <= new_B <= MAX_K and (new_A, new_B) not in lookup):
continue
if p != 0:
idxs = next(([(r, c)] for r, c in depths[d] if cnts[r][c]%2 == p%2), [])
if not idxs:
if p != 2:
continue
idxs = depths[d][:p]
lookup.add((new_A, new_B, new_d))
lookup.add((new_A, new_B))
new_q.append((new_A, new_B))
if (new_A, new_B) not in dp:
dp[new_A, new_B] = (idxs, (A, B))
Expand Down

0 comments on commit 4b768b9

Please sign in to comment.