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.

4 年之前
12345678910111213141516171819202122232425
  1. import collections
  2. import itertools
  3. import sys
  4. def recurse(n, sources, cache={0: 1}):
  5. if n not in cache:
  6. cache[n] = sum(recurse(m, sources) for m in sources[n])
  7. return cache[n]
  8. text = sys.stdin.read()
  9. ns = [int(n) for n in text.splitlines()]
  10. ns += [0, max(ns) + 3]
  11. ns.sort()
  12. a, b = collections.Counter([b - a for a, b in zip(ns, ns[1:])]).values()
  13. print(a * b)
  14. sources = collections.defaultdict(list)
  15. for a, b in itertools.combinations(ns, 2):
  16. if b - a <= 3:
  17. sources[b].append(a)
  18. print(recurse(ns[-1], sources))