結果
問題 |
No.1607 Kth Maximum Card
|
ユーザー |
|
提出日時 | 2021-10-04 09:37:50 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,250 bytes |
コンパイル時間 | 197 ms |
コンパイル使用メモリ | 82,432 KB |
実行使用メモリ | 81,024 KB |
最終ジャッジ日時 | 2024-07-22 09:00:12 |
合計ジャッジ時間 | 6,135 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 3 TLE * 1 -- * 29 |
ソースコード
def binary_search_int(ok,ng,test): """ :param ok: solve(x) = True を必ず満たす点 :param ng: solve(x) = False を必ず満たす点 """ while abs(ok-ng)>1: mid=(ok+ng)//2 if test(mid): ok=mid else: ng=mid return ok ############################################################## import sys input = sys.stdin.readline INF = 10**18 # 大きい数字 N, M, K = map(int, input().split()) edges=[[] for _ in range(N)] for _ in range(M): x, y, cost = map(int, input().split()) x-=1 y-=1 edges[x].append((y,cost)) edges[y].append((x,cost)) def test(k): next_set=[[] for _ in range(N)] next_set[0]=[0] dist=[INF]*(N+1) for time in range(N): while next_set[time]: p = next_set[time].pop() if dist[p]<time: continue for q,d in edges[p]: if d>k: cost=1 else: cost=0 if dist[q]<=time*cost: continue dist[q]=time+cost if q!=N-1: next_set[time+cost].append(q) return dist[N-1]<=K-1 kmin=binary_search_int(10**6,-1,test) print(kmin)