We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 22473db commit e6d9a4eCopy full SHA for e6d9a4e
2024/18/18.py
@@ -1,4 +1,5 @@
1
import networkx as nx
2
+from bisect import bisect
3
4
def solve(obstacles, S=70):
5
G = nx.grid_graph((S+1, S+1))
@@ -9,10 +10,5 @@ def solve(obstacles, S=70):
9
10
obstacles = [tuple(map(int, line.split(","))) for line in open(0)]
11
print(solve(obstacles[:1024])-1)
12
-lo, hi = 1024, len(obstacles)-1
13
-while lo < hi:
14
- mid = (lo + hi) // 2
15
- if solve(obstacles[:mid]): lo = mid+1
16
- else: hi = mid-1
17
-
18
-print(*obstacles[mid], sep=",")
+index = bisect(range(len(obstacles)), 0, key=lambda x: not solve(obstacles[:x]))
+print(*obstacles[index-1], sep=",")
0 commit comments