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.

25 lines
522B

  1. import sys
  2. text = sys.stdin.read()
  3. maps = {'R': -1, 'D': -1j, 'L': 1, 'U': 1j}
  4. info = []
  5. for path in text.splitlines():
  6. i, p = 0, 0
  7. best = {}
  8. for a, *n in path.split(','):
  9. d = maps[a]
  10. for _ in range(int(''.join(n))):
  11. i += 1
  12. p += d
  13. if p not in best:
  14. best[p] = i
  15. info.append(best)
  16. isect = set(info[0]) & set(info[1])
  17. print(int(min((abs(p.real) + abs(p.imag), p) for p in isect)[0]))
  18. print(min(info[0][p] + info[1][p] for p in isect))