File tree Expand file tree Collapse file tree 1 file changed +33
-6
lines changed Expand file tree Collapse file tree 1 file changed +33
-6
lines changed Original file line number Diff line number Diff line change 1
1
import networkx as nx
2
+ from collections import *
3
+
4
+
2
5
coords = {x + 1j * y : c for y , r in enumerate (open (0 )) for x , c in enumerate (r .strip ().replace ("." , " " ))}
3
6
4
7
d4 = [1 , 1j , - 1 , - 1j ]
12
15
13
16
S = [c for c in coords if coords [c ] in 'S' ][0 ]
14
17
E = [c for c in coords if coords [c ] in 'E' ][0 ]
15
- EL = nx .shortest_path_length (G , target = E )
18
+ # EL = nx.shortest_path_length(G, target=E)
16
19
SL = nx .shortest_path_length (G , source = S )
17
20
print (SL )
18
- print (EL )
19
- # exit()
20
- L = {l : max (EL [l ], SL [l ]) for l in EL }
21
+ # print(EL)
22
+ C = Counter ()
23
+
24
+ sl = list (SL .items ())
25
+ seen = set ()
26
+ s2 = 0
27
+ for i , (c1 , dist1 ) in enumerate (sl ):
28
+ for c2 , dist2 in sl [i + 1 :]:
29
+ diff = c2 - c1
30
+ diff = int (abs (diff .real ) + abs (diff .imag ))
31
+ if diff <= 20 :
32
+ D = dist2 - dist1 - diff
33
+ if D > 0 :
34
+ C [D ] += 1
35
+ if D >= 100 :
36
+ s2 += 1
37
+
38
+ for asd in sorted (C .items ()):
39
+ print (asd )
40
+
41
+ print (s2 )
42
+ exit ()
43
+ # L = {l: max(EL[l], SL[l]) for l in EL}
44
+
45
+ for c in coords :
46
+ for d in [1 , 1j , - 1 , - 1j ]:
47
+ if coords [c ] != '#' != coords [c + d ]:
48
+ G .add_edge (c , c + d )
49
+ G .add_edge ((c , 1 ), (c + d , 1 ))
21
50
22
51
# L = [el+sl for ]
23
52
24
53
# print(L)
25
54
# print(L[S])
26
55
# exit(0)
27
56
28
- from collections import *
29
-
30
57
C = Counter ()
31
58
32
59
s1 = 0
You can’t perform that action at this time.
0 commit comments