blob: 78e67e443649af52fb89f9611043bcf9d092311b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
from sys import stdin
def rot(a):
return [list(t) for t in zip(*a[::-1])]
def flatten(a):
return sum(a, [])
grid = [[int(c) for c in line.strip()] for line in stdin]
vis = [[0 for _ in a] for a in grid]
for _ in range(4):
for trees, to in zip(grid, vis):
highest = -1
for i in range(len(trees)):
if highest < trees[i]:
highest = trees[i]
to[i] += 1
grid = rot(grid)
vis = rot(vis)
print(len([c for c in flatten(vis) if c > 0]))
scores = [[1 for _ in a] for a in grid]
for _ in range(4):
for trees, to in zip(grid, scores):
lastBlock = [0] * 10
for i in range(len(trees)):
h = trees[i]
to[i] *= i - lastBlock[h]
for j in range(h + 1):
lastBlock[j] = i
grid = rot(grid)
scores = rot(scores)
print(max(flatten(scores)))
|