結果
問題 | No.2354 Poor Sight in Winter |
ユーザー |
|
提出日時 | 2023-04-11 11:40:11 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 887 ms / 2,000 ms |
コード長 | 1,538 bytes |
コンパイル時間 | 258 ms |
コンパイル使用メモリ | 82,260 KB |
実行使用メモリ | 282,892 KB |
最終ジャッジ日時 | 2024-10-07 03:52:58 |
合計ジャッジ時間 | 10,290 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 26 |
ソースコード
import sysfrom collections import deque, Counterinput = lambda: sys.stdin.readline().rstrip()ii = lambda: int(input())mi = lambda: map(int, input().split())li = lambda: list(mi())inf = 2 ** 63 - 1mod = 998244353def Dijkstra(s, graph):INF = 2 ** 63 - 1import heapqn = len(graph)dist = [INF] * ndist[s] = 0bef = [0] * nbef[s] = shq = [(0, s)]heapq.heapify(hq)while hq:c, now = heapq.heappop(hq)if c > dist[now]:continuefor to, cost in graph[now]:if dist[now] + cost < dist[to]:dist[to] = cost + dist[now]bef[to] = nowheapq.heappush(hq, (dist[to], + to))return dist, befdef DijkstraRest(bef, t):now = tret = []while bef[now] != now:ret.append((bef[now], now))now = bef[now]ret.reverse()return retn, k = mi()sx, sy, gx, gy = mi()XY = [(sx, sy), (gx, gy)] + [tuple(li()) for _ in range(n)]def check(x):graph = [[] for _ in range(n + 2)]for i in range(n + 2):x1, y1 = XY[i]for j in range(i + 1, n + 2):x2, y2 = XY[j]dist = abs(x2 - x1) + abs(y2 - y1)cost = (dist - 1) // xgraph[i].append((j, cost))graph[j].append((i, cost))d, _ = Dijkstra(0, graph)return d[1] <= kok = 10 ** 9ng = 0while abs(ok - ng) > 1:mid = (ok + ng) // 2if check(mid):ok = midelse:ng = midprint(ok)