結果

問題 No.1059 素敵な集合
ユーザー brthyyjpbrthyyjp
提出日時 2020-05-24 06:09:08
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,180 bytes
コンパイル時間 372 ms
コンパイル使用メモリ 82,156 KB
実行使用メモリ 374,648 KB
最終ジャッジ日時 2024-04-18 10:17:47
合計ジャッジ時間 10,299 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
59,460 KB
testcase_01 AC 39 ms
52,988 KB
testcase_02 AC 378 ms
96,228 KB
testcase_03 AC 43 ms
53,164 KB
testcase_04 AC 40 ms
52,704 KB
testcase_05 AC 41 ms
53,088 KB
testcase_06 AC 358 ms
91,284 KB
testcase_07 AC 347 ms
90,940 KB
testcase_08 AC 436 ms
98,500 KB
testcase_09 AC 193 ms
80,904 KB
testcase_10 AC 726 ms
114,464 KB
testcase_11 AC 339 ms
93,520 KB
testcase_12 AC 237 ms
85,076 KB
testcase_13 AC 627 ms
112,904 KB
testcase_14 AC 111 ms
77,180 KB
testcase_15 AC 1,326 ms
151,196 KB
testcase_16 AC 392 ms
95,868 KB
testcase_17 AC 337 ms
94,288 KB
testcase_18 AC 60 ms
74,856 KB
testcase_19 TLE -
testcase_20 -- -
testcase_21 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

def main():
    l, r = map(int, input().split())

    if l == 1:
        print(0)
        exit()

    n = r-l+1

    edge = [[] for _ in range(n)]
    used = set()
    for i in range(l, r+1):
        x = i-l
        j = i
        while j <= r:
            y = j-l
            if y != x:
                edge[x].append((0, y))
                edge[y].append((0, x))
                used.add(j)
            j += i
        if i != r:
            if i+1 not in used:
                y = x+1
                edge[x].append((1, y))
                #edge[y].append((1, x))

    import heapq
    def prim_heap():
        used = [True]*n
        edgelist = []
        for e in edge[0]:
            heapq.heappush(edgelist, e)
            used[0] = False
        res = 0
        while len(edgelist) != 0:
            minedge = heapq.heappop(edgelist)
            if not  used[minedge[1]]:
                continue
            v = minedge[1]
            used[v] = False
            for e in edge[v]:
                if used[e[1]]:
                    heapq.heappush(edgelist, e)
            res += minedge[0]
        return res

    print(prim_heap())

if __name__ == '__main__':
    main()
0