Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

20 lines
575B

  1. import math
  2. def combos(record, dist):
  3. a, b, c = 1, -record, dist
  4. x1, x2 = sorted([
  5. (-b + (b ** 2 - 4 * a * c) ** 0.5) / (2 * a),
  6. (-b - (b ** 2 - 4 * a * c) ** 0.5) / (2 * a),
  7. ])
  8. return int(x2) - int(x1)
  9. text = open(0).read()
  10. records, distances = [[int(n) for n in line.split()[1:]] for line in text.splitlines()]
  11. print(math.prod(combos(a, b)for a, b in zip(*[records, distances])))
  12. records, distances = [[int(''.join(line.split()[1:]))] for line in text.splitlines()]
  13. print(math.prod(combos(a, b)for a, b in zip(*[records, distances])))