Skip to content

Commit

Permalink
Second update as of 26 October 2024
Browse files Browse the repository at this point in the history
  • Loading branch information
RussellDash332 committed Oct 26, 2024
1 parent 3d96172 commit 0d5729a
Showing 1 changed file with 18 additions and 29 deletions.
47 changes: 18 additions & 29 deletions src/Pokémon Ice Maze/pokemon.py
Original file line number Diff line number Diff line change
@@ -1,35 +1,24 @@
import sys
from bisect import *
from array import *
C, R = map(int, sys.stdin.readline().split())
M = [*sys.stdin]; G = [array('i') for _ in range(R*C)]

import sys; from array import *
C, R = map(int, sys.stdin.readline().split()); S = array('h')
M = [*sys.stdin]; G = [array('i') for _ in range(R*C)]; K = (1, -1)
for i in range(R*C):
if M[i//C][i%C] == 'M': X = i
for i in range(1, R-1):
A = array('i')
for j in range(C):
if M[i][j] == 'M': X = C*i+j
if M[i][j] != '_': A.append(j)
for j in range(1, C-1):
if M[i][j] != '#': nx = A[bisect(A, j)]; G[C*i+nx-(M[i][nx]=='#')].append(C*i+j)
A = array('i')
for j in range(C, -1, -1):
if M[i][j] != '_': A.append(-j)
for j in range(C-2, 0, -1):
if M[i][j] != '#': nx = -A[bisect(A, -j)]; G[C*i+nx+(M[i][nx]=='#')].append(C*i+j)
for t in K:
for j in range(C)[::t]:
if M[i][j] != '_':
nx = j-t*(M[i][j]=='#')
while S: G[C*i+nx].append(C*i+S.pop())
if M[i][j] != '#': S.append(j)
for j in range(1, C-1):
A = array('i')
for i in range(R):
if M[i][j] != '_': A.append(i)
for i in range(1, R-1):
if M[i][j] != '#': nx = A[bisect(A, i)]; G[C*(nx-(M[nx][j]=='#'))+j].append(C*i+j)
A = array('i')
for i in range(R-1, -1, -1):
if M[i][j] != '_': A.append(-i)
for i in range(R-2, 0, -1):
if M[i][j] != '#': nx = -A[bisect(A, -i)]; G[C*(nx+(M[nx][j]=='#'))+j].append(C*i+j)

for t in K:
for i in range(R)[::t]:
if M[i][j] != '_':
nx = i-t*(M[i][j]=='#')
while S: G[C*nx+j].append(C*S.pop()+j)
if M[i][j] != '#': S.append(i)
D = array('i', [-1]*R*C); D[X] = 0; Q = array('i', [X])
for u in Q:
for v in G[u]:
if D[v] == -1: D[v] = D[u]+1; Q.append(v)
print(*D)
for i in D: print(i)

0 comments on commit 0d5729a

Please sign in to comment.