結果

問題 No.1607 Kth Maximum Card
ユーザー あかしあみどりあかしあみどり
提出日時 2023-02-20 22:39:21
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 2,700 ms / 3,500 ms
コード長 2,040 bytes
コンパイル時間 404 ms
コンパイル使用メモリ 87,216 KB
実行使用メモリ 258,544 KB
最終ジャッジ日時 2023-09-28 18:12:12
合計ジャッジ時間 31,883 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 76 ms
71,196 KB
testcase_01 AC 78 ms
71,412 KB
testcase_02 AC 77 ms
71,412 KB
testcase_03 AC 77 ms
71,052 KB
testcase_04 AC 77 ms
71,480 KB
testcase_05 AC 77 ms
71,484 KB
testcase_06 AC 76 ms
71,564 KB
testcase_07 AC 77 ms
71,384 KB
testcase_08 AC 1,779 ms
135,320 KB
testcase_09 AC 1,186 ms
126,932 KB
testcase_10 AC 2,700 ms
157,196 KB
testcase_11 AC 292 ms
91,184 KB
testcase_12 AC 1,522 ms
129,184 KB
testcase_13 AC 265 ms
85,364 KB
testcase_14 AC 354 ms
88,236 KB
testcase_15 AC 1,227 ms
129,780 KB
testcase_16 AC 306 ms
86,420 KB
testcase_17 AC 149 ms
79,292 KB
testcase_18 AC 939 ms
114,432 KB
testcase_19 AC 560 ms
98,244 KB
testcase_20 AC 738 ms
106,492 KB
testcase_21 AC 811 ms
107,580 KB
testcase_22 AC 1,914 ms
150,928 KB
testcase_23 AC 1,890 ms
151,092 KB
testcase_24 AC 836 ms
95,528 KB
testcase_25 AC 451 ms
88,532 KB
testcase_26 AC 694 ms
91,576 KB
testcase_27 AC 849 ms
96,188 KB
testcase_28 AC 693 ms
93,296 KB
testcase_29 AC 1,647 ms
115,972 KB
testcase_30 AC 2,424 ms
140,832 KB
testcase_31 AC 1,564 ms
110,216 KB
testcase_32 AC 484 ms
179,708 KB
testcase_33 AC 481 ms
165,148 KB
testcase_34 AC 812 ms
258,544 KB
testcase_35 AC 623 ms
232,320 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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, i))
    maps[b-1].append((a-1,i))
    cost_dict.append(c)
# 以下の問題にてテスト済み
# 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, ind in maps[node]:
                if use_node[ind] == 0:
                    use_node[ind] = -1
                    if cost_dict[ind] > 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)
0