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.

2 yıl önce
123456789101112131415161718192021222324252627282930
  1. import collections
  2. import itertools
  3. text = open(0).read()
  4. path = []
  5. dirs = collections.defaultdict(int)
  6. for line in map(str.split, text.splitlines()):
  7. match line:
  8. case ('$', 'cd', '..'):
  9. path.pop()
  10. case ('$', 'cd', loc):
  11. path.append(loc)
  12. case ('$', 'ls'):
  13. pass
  14. case ('dir', _):
  15. pass
  16. case (size, _):
  17. for leg in itertools.accumulate(path):
  18. dirs[leg] += int(size)
  19. ans1 = sum(size for size in dirs.values() if size <= 100_000)
  20. print(ans1)
  21. free = 70_000_000 - dirs['/']
  22. ans2 = min(size for size in dirs.values() if free + size >= 30_000_000)
  23. print(ans2)