blob: 07caa7210c5d11a26e26c17f7ef1dafcd953c989 (
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
import sys
infile = sys.argv[1] if len(sys.argv) > 1 else "data/8_2022.txt"
data = open(infile).read().strip()
lines = [x for x in data.split("\n")]
g = []
for line in lines:
row = line
g.append(row)
dir = [(-1, 0), (0, 1), (1, 0), (0, -1)]
r = len(g)
c = len(g[0])
p1 = 0
p2 = 0
for i in range(r):
for j in range(c):
vis = False
for dr, dc in dir:
rr = i
cc = j
ok = True
while True:
rr += dr
cc += dc
if not (0 <= rr < r and 0 <= cc < c):
break
if g[rr][cc] >= g[i][j]:
ok = False
if ok:
vis = True
if vis:
p1 += 1
for i in range(r):
for j in range(c):
score = 1
for dr, dc in dir:
dist = 1
rr = i + dr
cc = j + dc
while True:
if not (0 <= rr < r and 0 <= cc < c):
dist -= 1
break
if g[rr][cc] >= g[i][j]:
break
dist += 1
rr += dr
cc += dc
score *= dist
p2 = max(p2, score)
print(p1)
print(p2)
|