您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

2 年前
123456789101112131415161718192021222324252627282930313233
  1. from itertools import count, takewhile
  2. def heights(t, dt):
  3. return takewhile(lambda h: h is not None, (grid.get(t + dt * i) for i in count(1)))
  4. def is_visible(t):
  5. return any(grid[t] > max(heights(t, dt), default=-1) for dt in udlr)
  6. def score(t):
  7. score = 1
  8. for dt in udlr:
  9. count = 0
  10. for h in heights(t, dt):
  11. count += 1
  12. if h >= grid[t]:
  13. break
  14. score *= count
  15. return score
  16. udlr = [-1j, 1j, -1, 1]
  17. text = open(0).read()
  18. grid = {complex(x, y): int(v) for y, line in enumerate(text.splitlines(), 1) for x, v in enumerate(line, 1)}
  19. ans1 = sum(is_visible(t) for t in grid)
  20. print(ans1)
  21. ans2 = max(score(t) for t in grid)
  22. print(ans2)