No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

41 líneas
1.3KB

  1. def reflect(pos, dirx):
  2. match '-' if dirx.real else '|', graph.get(pos, ' '):
  3. case [_, ' ']: return []
  4. case [_, '.']: return [0]
  5. case ['-', '-']: return [0]
  6. case ['-', 'L']: return [1]
  7. case ['-', '/']: return [-1]
  8. case ['-', '|']: return [1, -1]
  9. case ['|', '|']: return [0]
  10. case ['|', '/']: return [1]
  11. case ['|', 'L']: return [-1]
  12. case ['|', '-']: return [1, -1]
  13. case other: raise RuntimeError(other)
  14. def solve(start):
  15. seen = set()
  16. state = {start}
  17. while state:
  18. seen |= state
  19. state = {(pp + dd * 1j ** rr, dd * 1j ** rr) for pp, dd in state for rr in reflect(pp, dd)} - seen
  20. return len({x for x, y in seen} & set(graph))
  21. text = open(0).read().replace('\\', 'L')
  22. graph = {
  23. complex(x, y): val
  24. for y, row in enumerate(text.splitlines())
  25. for x, val in enumerate(row)
  26. }
  27. print(solve((0, 1)))
  28. xmin, *_, xmax = sorted(int(p.real) for p in graph)
  29. ymin, *_, ymax = sorted(int(p.imag) for p in graph)
  30. starts = []
  31. starts += [(complex(x, ymin), 1j) for x in range(xmin, xmax + 1)]
  32. starts += [(complex(x, ymax),-1j) for x in range(xmin, xmax + 1)]
  33. starts += [(complex(xmin, y), 1 ) for y in range(ymin, ymax + 1)]
  34. starts += [(complex(xmax, y),-1 ) for y in range(ymin, ymax + 1)]
  35. print(max(solve(start) for start in starts))