結果
| 問題 |
No.2354 Poor Sight in Winter
|
| コンテスト | |
| ユーザー |
H20
|
| 提出日時 | 2023-06-16 23:03:18 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 1,463 ms / 2,000 ms |
| コード長 | 1,543 bytes |
| コンパイル時間 | 149 ms |
| コンパイル使用メモリ | 82,264 KB |
| 実行使用メモリ | 306,276 KB |
| 最終ジャッジ日時 | 2024-06-24 16:07:16 |
| 合計ジャッジ時間 | 15,488 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 26 |
ソースコード
import collections
import heapq
N,K = map(int, input().split())
sx,sy,gx,gy = map(int, input().split())
XY = [list(map(int, input().split())) for _ in range(N)]
XY.append([sx,sy])
XY.append([gx,gy])
def is_ok(P):
G = Dijkstra()
for i in range(N+2):
for j in range(i+1,N+2):
temp = abs(XY[i][0]-XY[j][0])+abs(XY[i][1]-XY[j][1])
G.add(i,j,-(-temp//P)-1)
D = G.search(N)
return D[N+1]<=K
def meguru_bisect(ng, ok):
while (abs(ok - ng) > 1):
mid = (ok + ng) // 2
if is_ok(mid):
ok = mid
else:
ng = mid
return ok
class Dijkstra:
def __init__(self):
self.e = collections.defaultdict(list)
def add(self, u, v, d):
self.e[u].append([v, d])
self.e[v].append([u, d])
def delete(self, u, v):
self.e[u] = [_ for _ in self.e[u] if _[0] != v]
self.e[v] = [_ for _ in self.e[v] if _[0] != u]
def search(self, s):
d = collections.defaultdict(lambda: 10**6+10)
d[s] = 0
q = []
heapq.heappush(q, (0, s))
v = collections.defaultdict(bool)
while len(q):
k, u = heapq.heappop(q)
if v[u]:
continue
v[u] = True
for uv, ud in self.e[u]:
if v[uv]:
continue
vd = k + ud
if d[uv] > vd:
d[uv] = vd
heapq.heappush(q, (vd, uv))
return d
print(meguru_bisect(0,2*10**5+1000))
H20