結果
問題 | No.1607 Kth Maximum Card |
ユーザー | あかしあみどり |
提出日時 | 2023-02-20 22:26:59 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
|
実行時間 | - |
コード長 | 2,731 bytes |
コンパイル時間 | 292 ms |
コンパイル使用メモリ | 87,152 KB |
実行使用メモリ | 266,148 KB |
最終ジャッジ日時 | 2023-09-28 17:50:37 |
合計ジャッジ時間 | 12,058 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge13 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 95 ms
71,736 KB |
testcase_01 | AC | 94 ms
71,668 KB |
testcase_02 | AC | 98 ms
71,592 KB |
testcase_03 | AC | 92 ms
71,660 KB |
testcase_04 | AC | 94 ms
71,736 KB |
testcase_05 | AC | 95 ms
71,580 KB |
testcase_06 | AC | 94 ms
71,744 KB |
testcase_07 | AC | 94 ms
71,708 KB |
testcase_08 | AC | 2,790 ms
246,536 KB |
testcase_09 | AC | 1,944 ms
233,196 KB |
testcase_10 | TLE | - |
testcase_11 | -- | - |
testcase_12 | -- | - |
testcase_13 | -- | - |
testcase_14 | -- | - |
testcase_15 | -- | - |
testcase_16 | -- | - |
testcase_17 | -- | - |
testcase_18 | -- | - |
testcase_19 | -- | - |
testcase_20 | -- | - |
testcase_21 | -- | - |
testcase_22 | -- | - |
testcase_23 | -- | - |
testcase_24 | -- | - |
testcase_25 | -- | - |
testcase_26 | -- | - |
testcase_27 | -- | - |
testcase_28 | -- | - |
testcase_29 | -- | - |
testcase_30 | -- | - |
testcase_31 | -- | - |
testcase_32 | -- | - |
testcase_33 | -- | - |
testcase_34 | -- | - |
testcase_35 | -- | - |
ソースコード
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)) # # K 未満の時 # from collections import deque # reached = [0] * N ## 1つ前のノードを持たせると微妙に遅くなるのでやめよう # deq = deque([[0,0]]) # mins = float("inf") # while deq: # node, count = deq.pop() #BFS # if node == N-1: # if count < K : # mins = 0 # break # reached[node] = -1 # for next_node, cost in maps[node]: # # 訪問済み判定 # if reached[next_node] == -1: # continue # if count+1 <= K: # mins = min(mins, cost) # reached[next_node] = -1 # deq.append([next_node, count+1]) # 以下の問題にてテスト済み # https://atcoder.jp/contests/abc213/tasks/abc213_e from collections import deque def zero_one_dfs(target, K): zero_deq = deque([0]) count=0 use_node = set([]) while True: one_deq = deque([]) 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 ind not in use_node: use_node.add(ind) 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 # if mins != 0: mins = meguru_bisect(-1, 2*10**5 + 1) print(mins)