blob: c7bb47de028c97825679e297b4465250203396a1 (
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
|
from collections import defaultdict
from fileinput import input
from itertools import product
antennas = defaultdict(set)
x_max, y_max = 0, 0
for idy, line in enumerate(input()):
y_max = max(y_max, idy)
for idx, c in enumerate(line.strip()):
x_max = max(x_max, idx)
if c == ".":
continue
antennas[c].add(complex(idx, idy))
nodes = set()
for vs in antennas.values():
for v1, v2 in product(vs, vs):
if v1 == v2:
continue
vec = v2 - v1
nodes.add(v1 + 2 * vec)
nodes.add(v2 - 2 * vec)
nodes = {n for n in nodes if 0 <= n.real <= x_max and 0 <= n.imag <= y_max}
gold_nodes = set()
for vs in antennas.values():
for v1, v2 in product(vs, vs):
if v1 == v2:
continue
vec = v2 - v1
start = v1
while 0 <= start.real <= x_max and 0 <= start.imag <= y_max:
gold_nodes.add(start)
start += vec
start = v2
while 0 <= start.real <= x_max and 0 <= start.imag <= y_max:
gold_nodes.add(start)
start -= vec
silver = len(nodes)
gold = len(gold_nodes)
print("silver:", silver)
print("gold:", gold)
|