結果

問題 No.2354 Poor Sight in Winter
ユーザー flygonflygon
提出日時 2023-06-16 22:35:38
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 730 ms / 2,000 ms
コード長 1,206 bytes
コンパイル時間 446 ms
コンパイル使用メモリ 87,200 KB
実行使用メモリ 103,428 KB
最終ジャッジ日時 2023-09-06 20:56:07
合計ジャッジ時間 10,470 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 92 ms
71,528 KB
testcase_01 AC 97 ms
71,548 KB
testcase_02 AC 93 ms
71,560 KB
testcase_03 AC 96 ms
71,400 KB
testcase_04 AC 93 ms
71,600 KB
testcase_05 AC 96 ms
71,876 KB
testcase_06 AC 97 ms
71,728 KB
testcase_07 AC 94 ms
71,568 KB
testcase_08 AC 94 ms
71,712 KB
testcase_09 AC 114 ms
77,108 KB
testcase_10 AC 108 ms
77,212 KB
testcase_11 AC 483 ms
101,660 KB
testcase_12 AC 462 ms
101,096 KB
testcase_13 AC 672 ms
103,428 KB
testcase_14 AC 730 ms
103,280 KB
testcase_15 AC 628 ms
102,588 KB
testcase_16 AC 683 ms
101,960 KB
testcase_17 AC 650 ms
103,204 KB
testcase_18 AC 368 ms
87,572 KB
testcase_19 AC 526 ms
95,076 KB
testcase_20 AC 411 ms
88,804 KB
testcase_21 AC 190 ms
79,432 KB
testcase_22 AC 317 ms
83,856 KB
testcase_23 AC 328 ms
84,552 KB
testcase_24 AC 488 ms
92,060 KB
testcase_25 AC 266 ms
82,432 KB
testcase_26 AC 234 ms
80,916 KB
testcase_27 AC 158 ms
78,672 KB
testcase_28 AC 192 ms
80,008 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
sys.setrecursionlimit(5*10**5)
input = sys.stdin.readline
from collections import defaultdict, deque, Counter
from heapq import heappop, heappush
from bisect import bisect_left, bisect_right
from math import gcd

n,k = map(int,input().split())
sx,sy,gx,gy = map(int,input().split())
xy = [[sx,sy]]
for i in range(n):
    xy.append(list(map(int,input().split())))
xy.append([gx,gy])
graph = [[] for i in range(n+2)]

for i in range(n+2):
    xi,yi = xy[i]
    for j in range(n+2):
        xj,yj = xy[j]
        if i == j: continue
        graph[i].append([j,abs(xi-xj) + abs(yi-yj)])


#ダイクストラ法
def dijkstra(s,n, p): # sがスタート、nが頂点数
    INF = 10**15
    dist = [INF]*(n+1)
    que = [(0,s)]
    dist[s] = 0
    while que:
        c,crr = heappop(que)
        if c > dist[crr]: continue
        for nxt, cost in graph[crr]:
            cnt = (cost-1)//p
            if dist[crr] + cnt < dist[nxt]:
                dist[nxt] = dist[crr] + cnt
                heappush(que,(dist[nxt],nxt))
    return dist[-2]

l = 1
r = 10**6

for i in range(40):
    m = (l+r)//2
    cnt = dijkstra(0, n+2, m)
    if cnt <= k:
        r = m
    else:
        l = m
    
print(r)


0