結果
問題 | No.1607 Kth Maximum Card |
ユーザー |
|
提出日時 | 2023-02-20 22:35:29 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 3,285 ms / 3,500 ms |
コード長 | 2,018 bytes |
コンパイル時間 | 351 ms |
コンパイル使用メモリ | 81,840 KB |
実行使用メモリ | 258,200 KB |
最終ジャッジ日時 | 2024-07-21 12:42:19 |
合計ジャッジ時間 | 30,710 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 33 |
ソースコード
def oi(): return int(input()) def os(): return input() def mi(): return list(map(int, input().split())) import sys input = sys.stdin.readline # import sys # sys.setrecursionlimit(10**8) # import pypyjit # pypyjit.set_param('max_unroll_recursion=-1') input_count = 0 input_count = 0 N,M,K = mi() NODE = N LOOP_NUM = M maps = {i:[] for i in range(NODE)} cost_dict = {} for i in range(LOOP_NUM): a,b,c = mi() maps[a-1].append((b-1, c, i)) maps[b-1].append((a-1,c, i)) # 以下の問題にてテスト済み # https://atcoder.jp/contests/abc213/tasks/abc213_e def zero_one_dfs(target, K): zero_deq = [0] count=0 use_node = [0] * M while True: one_deq = [] while zero_deq: node = zero_deq.pop() # 目的地に到達したら if node == N-1: if count < K: return True # コスト0の時の移動パターン for next_node, cost, ind in maps[node]: if use_node[ind] == 0: use_node[ind] = -1 if cost > target: one_deq.append(next_node) else: zero_deq.append(next_node) count+=1 zero_deq = one_deq[:] if count >= K: return False def is_ok(arg): # 条件を満たすかどうか?問題ごとに定義 # 初めてFalseからTrueになるTrueの地点を取得 return zero_one_dfs(arg, K) def meguru_bisect(ng, ok): ''' 初期値のng,okを受け取り,is_okを満たす最小(最大)のokを返す まずis_okを定義すべし ng ok は とり得る最小の値-1 とり得る最大の値+1 最大最小が逆の場合はよしなにひっくり返す ''' while (abs(ok - ng) > 1): mid = (ok + ng) // 2 if is_ok(mid): ok = mid else: ng = mid return ok mins = meguru_bisect(-1, 2*10**5 + 1) print(mins)