結果

問題 No.1059 素敵な集合
ユーザー brthyyjpbrthyyjp
提出日時 2020-05-24 06:00:35
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,060 bytes
コンパイル時間 163 ms
コンパイル使用メモリ 82,368 KB
実行使用メモリ 401,620 KB
最終ジャッジ日時 2024-04-18 09:55:33
合計ジャッジ時間 10,709 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
60,564 KB
testcase_01 AC 37 ms
52,644 KB
testcase_02 AC 421 ms
106,756 KB
testcase_03 AC 41 ms
54,040 KB
testcase_04 AC 38 ms
52,888 KB
testcase_05 AC 37 ms
53,264 KB
testcase_06 AC 349 ms
98,688 KB
testcase_07 AC 345 ms
98,712 KB
testcase_08 AC 445 ms
109,788 KB
testcase_09 AC 194 ms
83,260 KB
testcase_10 AC 775 ms
128,024 KB
testcase_11 AC 383 ms
102,532 KB
testcase_12 AC 227 ms
88,524 KB
testcase_13 AC 748 ms
131,216 KB
testcase_14 AC 113 ms
78,332 KB
testcase_15 AC 1,417 ms
176,596 KB
testcase_16 AC 398 ms
104,812 KB
testcase_17 AC 396 ms
103,536 KB
testcase_18 AC 91 ms
93,364 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)]
    for i in range(l, r+1):
        x = i-l
        j = i
        while j <= r:
            y = j-l
            edge[x].append((0, y))
            edge[y].append((0, x))
            j += i
        if i != r:
            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