結果

問題 No.1059 素敵な集合
ユーザー MisterMister
提出日時 2020-05-20 00:37:08
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 737 bytes
コンパイル時間 241 ms
コンパイル使用メモリ 82,452 KB
実行使用メモリ 78,488 KB
最終ジャッジ日時 2024-04-09 22:47:47
合計ジャッジ時間 2,514 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 34 ms
53,092 KB
testcase_01 AC 63 ms
68,100 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 34 ms
53,868 KB
testcase_05 AC 33 ms
53,500 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 46 ms
66,020 KB
testcase_19 AC 88 ms
76,400 KB
testcase_20 WA -
testcase_21 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

# 経路圧縮さぼったver.
class UnionFind:
    def __init__(self, n):
        self.par = [i for i in range(n)]
        self.size = [1 for i in range(n)]

    def find(self, v):
        return self.par[v]

    def unite(self, u, v):
        u = self.find(u)
        v = self.find(v)
        if u == v:
            return

        if self.size[u] < self.size[v]:
            u, v = v, u

        self.size[u] += self.size[v]
        self.par[v] = u


l, r = list(map(int, input().split()))

uf = UnionFind(r + 1)

for x in range(l, r + 1):
    y = x * 2
    while y <= r:
        uf.unite(x, y)
        y += x

ans = 0
for x in range(l, r):
    if uf.find(x) != uf.find(x + 1):
        ans += 1
        uf.unite(x, x + 1)

print(ans)
0