|
| 1 | +import networkx as nx |
| 2 | +coords = {x+1j*y: c for y, r in enumerate(open(0)) for x, c in enumerate(r.strip().replace(".", " "))} |
| 3 | + |
| 4 | +d4 = [1, 1j, -1, -1j] |
| 5 | + |
| 6 | +G = nx.Graph() |
| 7 | +for c in coords: |
| 8 | + for d in [1, 1j, -1, -1j]: |
| 9 | + if coords[c] != '#' != coords[c+d]: |
| 10 | + G.add_edge(c, c+d) |
| 11 | + # G.add_edge((c, 1), (c+d, 1)) |
| 12 | + |
| 13 | +S = [c for c in coords if coords[c] in 'S'][0] |
| 14 | +E = [c for c in coords if coords[c] in 'E'][0] |
| 15 | +EL = nx.shortest_path_length(G, target=E) |
| 16 | +SL = nx.shortest_path_length(G, source=S) |
| 17 | +print(SL) |
| 18 | +print(EL) |
| 19 | +# exit() |
| 20 | +L = {l: max(EL[l], SL[l]) for l in EL} |
| 21 | + |
| 22 | +# L = [el+sl for ] |
| 23 | + |
| 24 | +# print(L) |
| 25 | +# print(L[S]) |
| 26 | +# exit(0) |
| 27 | + |
| 28 | +from collections import * |
| 29 | + |
| 30 | +C = Counter() |
| 31 | + |
| 32 | +s1 = 0 |
| 33 | +seen= set() |
| 34 | +for c in coords: |
| 35 | + for d in [1, 1j, -1, -1j]: |
| 36 | + for d2 in [d]: |
| 37 | + diff = 0 |
| 38 | + for d3 in [0]: |
| 39 | + c2 = c+d+d2+d3 |
| 40 | + if c2 in coords and coords[c] != '#' != coords[c2] and c != c2: |
| 41 | + delta = d+d2+d3 |
| 42 | + new = SL[c2] - SL[c] - int(abs(delta.imag) + abs(delta.real)) |
| 43 | + print("\t", d3, new) |
| 44 | + diff = max(diff, new) |
| 45 | + if (c, c+d+d2) not in seen and diff > 0: |
| 46 | + seen.add((c, c+d+d2)) |
| 47 | + seen.add((c+d+d2, c)) |
| 48 | + if diff > 0: |
| 49 | + # print(c, c2) |
| 50 | + C[diff] += 1 |
| 51 | + if diff >= 30: |
| 52 | + print(diff) |
| 53 | + for y in range(15): |
| 54 | + for x in range(15): |
| 55 | + X=x+y*1j |
| 56 | + print(end=coords[X] if X not in [c, c+d+d2] else "!") |
| 57 | + print(end=f"{SL.get(X, '##'):2}") |
| 58 | + print() |
| 59 | + print() |
| 60 | + if diff >= 100: |
| 61 | + s1 += 1 |
| 62 | + |
| 63 | + |
| 64 | +for asd in sorted(C.items()): |
| 65 | + print(asd) |
| 66 | + |
| 67 | +# 536 |
| 68 | +# 677 |
| 69 | +# 1923 |
| 70 | + |
| 71 | + |
| 72 | +# for path in nx.all_simple_paths(G, S, (E, 1), cutoff=L): |
| 73 | +# if L - len(path) >= 100: |
| 74 | +# s1 += 1 |
| 75 | +print(s1) |
| 76 | +# paths = list(nx.all_shortest_paths(G, S, (E, 0), "weight")) |
| 77 | + |
| 78 | +# print(sum(G.edges[e]["weight"] for e in zip(paths[0], paths[0][1:]))) |
| 79 | +# print(len({p[0] for p in sum(paths, [])})) |
0 commit comments