結果
| 問題 |
No.2354 Poor Sight in Winter
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2023-04-11 11:39:27 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 1,539 bytes |
| コンパイル時間 | 391 ms |
| コンパイル使用メモリ | 82,456 KB |
| 実行使用メモリ | 283,008 KB |
| 最終ジャッジ日時 | 2024-10-07 03:51:57 |
| 合計ジャッジ時間 | 11,425 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 18 RE * 8 |
ソースコード
import sys
from collections import deque, Counter
input = lambda: sys.stdin.readline().rstrip()
ii = lambda: int(input())
mi = lambda: map(int, input().split())
li = lambda: list(mi())
inf = 2 ** 63 - 1
mod = 998244353
def Dijkstra(s, graph):
INF = 2 ** 63 - 1
import heapq
n = len(graph)
dist = [INF] * n
dist[s] = 0
bef = [0] * n
bef[s] = s
hq = [(0, s)]
heapq.heapify(hq)
while hq:
c, now = heapq.heappop(hq)
if c > dist[now]:
continue
for to, cost in graph[now]:
if dist[now] + cost < dist[to]:
dist[to] = cost + dist[now]
bef[to] = now
heapq.heappush(hq, (dist[to], + to))
return dist, bef
def DijkstraRest(bef, t):
now = t
ret = []
while bef[now] != now:
ret.append((bef[now], now))
now = bef[now]
ret.reverse()
return ret
n, 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) // x
graph[i].append((j, cost))
graph[j].append((i, cost))
d, _ = Dijkstra(0, graph)
return d[1] <= k
ok = 10 ** 9
ng = -1
while abs(ok - ng) > 1:
mid = (ok + ng) // 2
if check(mid):
ok = mid
else:
ng = mid
print(ok)