結果

問題 No.1059 素敵な集合
ユーザー RITIK KUMAR GUPTARITIK KUMAR GUPTA
提出日時 2020-05-24 13:52:20
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 1,006 bytes
コンパイル時間 415 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 308,480 KB
最終ジャッジ日時 2024-04-19 20:47:52
合計ジャッジ時間 4,093 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 26 ms
16,128 KB
testcase_01 TLE -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
readline = sys.stdin.readline

class UF():
    def __init__(self, num):
        self.par = [-1]*num
    def find(self, x):
        if self.par[x] < 0:
            return x
        else:
            stack = []
            while self.par[x] >= 0:
                stack.append(x)
                x = self.par[x]
            for xi in stack:
                self.par[xi] = x
            return x
    
    def union(self, x, y):
        rx = self.find(x)
        ry = self.find(y)
        if rx != ry:
            if self.par[rx] > self.par[ry]:
                rx, ry = ry, rx
            self.par[rx] += self.par[ry]
            self.par[ry] = rx
            return True
        return False

L, R = map(int, readline().split())
R += 1

Edge = []
for x in range(L, R):
    for k in range(2, -(-R//x)):
        Edge.append((0, x-L, x*k-L))
for x in range(L, R-1):
    Edge.append((1, x-L, x+1-L))
T = UF(R-L)
Edge.sort()
ans = 0
for c, a, b in Edge:
    if T.union(a, b):
        ans += c
print(ans)
0