You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

2 年之前
2 年之前
2 年之前
2 年之前
2 年之前
2 年之前
2 年之前
2 年之前
2 年之前
2 年之前
2 年之前
2 年之前
2 年之前
2 年之前
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. import re
  2. def transform(pos, drx, rotations, size, X, Y):
  3. x, y = pos.real % size, pos.imag % size
  4. for _ in range(rotations % 4):
  5. x, y = size - 1 - y, x
  6. return size * complex(X, Y) + complex(x, y), drx * 1j ** rotations
  7. def wrap1(pos, drx, size):
  8. x, y = pos.real, pos.imag
  9. match x // 50, y // 50, drx:
  10. case 0, 0, -1 : return size * 2 + pos, -1
  11. case 0, 1, -1 : return size * 1 + pos, -1
  12. case 0, 1, -1j: return size * 2j + pos, -1j
  13. case 0, 4, 1j: return size * -2j + pos, 1j
  14. case 1, 3, 1 : return size * -1 + pos, 1
  15. case 1, 3, 1j: return size * -3j + pos, 1j
  16. case 1, -1, -1j: return size * 3j + pos, -1j
  17. case 2, 1, 1 : return size * -1 + pos, 1
  18. case 2, 1, 1j: return size * -1j + pos, 1j
  19. case 2, 2, 1 : return size * -2 + pos, 1
  20. case 2, -1, -1j: return size * 1j + pos, -1j
  21. case 3, 0, 1 : return size * -2 + pos, 1
  22. case -1, 2, -1 : return size * 2 + pos, -1
  23. case -1, 3, -1 : return size * 1 + pos, -1
  24. def wrap2(pos, drx, size):
  25. x, y = pos.real, pos.imag
  26. match x // 50, y // 50, drx:
  27. case 0, 0, -1 : return transform(pos, drx, 2, size, 0, 2)
  28. case -1, 2, -1 : return transform(pos, drx, 2, size, 1, 0)
  29. case 1, -1, -1j: return transform(pos, drx, 1, size, 0, 3)
  30. case 2, 1, 1 : return transform(pos, drx, -1, size, 2, 0)
  31. case 0, 1, -1j: return transform(pos, drx, 1, size, 1, 1)
  32. case 1, 3, 1 : return transform(pos, drx, -1, size, 1, 2)
  33. case 2, 2, 1 : return transform(pos, drx, 2, size, 2, 0)
  34. case 1, 3, 1j: return transform(pos, drx, 1, size, 0, 3)
  35. case 0, 4, 1j: return transform(pos, drx, 0, size, 2, 0)
  36. case 0, 1, -1 : return transform(pos, drx, -1, size, 0, 2)
  37. case -1, 3, -1 : return transform(pos, drx, -1, size, 1, 0)
  38. case 2, -1, -1j: return transform(pos, drx, 0, size, 0, 3)
  39. case 2, 1, 1j: return transform(pos, drx, 1, size, 1, 1)
  40. case 3, 0, 1 : return transform(pos, drx, 2, size, 1, 2)
  41. def main(text, v, wrap):
  42. *grid, _, path = text.splitlines()
  43. grid = {complex(x, y): c for y, l in enumerate(grid)
  44. for x, c in enumerate(l) if c in '.#'}
  45. pos, drx = min(grid, key=lambda pos: (pos.imag, pos.real)), 1
  46. size = int((len(grid) / 6) ** 0.5)
  47. for move in re.findall(r'\d+|R|L', path):
  48. match move:
  49. case 'L':
  50. drx *= -1j
  51. case 'R':
  52. drx *= +1j
  53. case _:
  54. for _ in range(int(move)):
  55. p, d = pos + drx, drx
  56. if p not in grid:
  57. p, d = wrap(p, d, size)
  58. if grid[p] == '.':
  59. pos, drx = p, d
  60. return int(1000 * (pos.imag + 1) + 4 * (pos.real + 1) + [1, 1j, -1, -1j].index(drx))
  61. text = open(0).read()
  62. ans1 = main(text, 1, wrap1)
  63. print(ans1)
  64. ans2 = main(text, 2, wrap2)
  65. print(ans2)