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.

28 satır
500B

  1. import sys
  2. def is_open(x, y):
  3. n = x*x + 3*x + 2*x*y + y + y*y + inp
  4. return f'{n:b}'.count('1') % 2 == 0
  5. inp = int(sys.stdin.read())
  6. valid = {
  7. complex(x, y)
  8. for y in range(50)
  9. for x in range(50)
  10. if is_open(x, y)
  11. }
  12. steps = (1, -1, 1j, -1j)
  13. edge = {1 + 1j}
  14. seen = set()
  15. hop = 0
  16. while 31 + 39j not in seen:
  17. edge = {old + step for old in edge for step in steps} & valid - seen
  18. seen |= edge
  19. hop += 1
  20. if hop == 50:
  21. ans2 = len(seen)
  22. print(hop)
  23. print(ans2)