結果

問題 No.1059 素敵な集合
ユーザー nephrologistnephrologist
提出日時 2020-05-22 23:43:21
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 134 ms / 2,000 ms
コード長 889 bytes
コンパイル時間 300 ms
コンパイル使用メモリ 86,968 KB
実行使用メモリ 78,656 KB
最終ジャッジ日時 2023-09-30 15:34:53
合計ジャッジ時間 3,686 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 77 ms
71,420 KB
testcase_01 AC 109 ms
77,644 KB
testcase_02 AC 122 ms
77,660 KB
testcase_03 AC 74 ms
71,436 KB
testcase_04 AC 75 ms
71,188 KB
testcase_05 AC 76 ms
71,156 KB
testcase_06 AC 119 ms
77,424 KB
testcase_07 AC 120 ms
77,676 KB
testcase_08 AC 120 ms
77,916 KB
testcase_09 AC 116 ms
77,576 KB
testcase_10 AC 121 ms
77,844 KB
testcase_11 AC 119 ms
77,560 KB
testcase_12 AC 127 ms
77,224 KB
testcase_13 AC 126 ms
78,168 KB
testcase_14 AC 82 ms
76,060 KB
testcase_15 AC 134 ms
78,628 KB
testcase_16 AC 119 ms
77,924 KB
testcase_17 AC 122 ms
77,512 KB
testcase_18 AC 77 ms
76,436 KB
testcase_19 AC 125 ms
77,844 KB
testcase_20 AC 134 ms
78,424 KB
testcase_21 AC 131 ms
78,656 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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


# union-find
# xの根を求める


def find(x):
    if par[x] < 0:
        return x
    else:
        par[x] = find(par[x])
        return par[x]


# xとyの属する集合の併合
def unite(x, y):
    x = find(x)
    y = find(y)
    if x == y:
        return False
    else:
        # sizeの大きい方をxとする
        if par[x] > par[y]:
            x, y = y, x
        par[x] += par[y]
        par[y] = x
        return True


# xとyが同じ集合か判定
def is_same(x, y):
    return find(x) == find(y)


def size(x):
    return -par[find(x)]


# 初期化
# 根なら-size、子なら親の頂点
par = [-1] * (r - l + 1)

cnt = 0
# cost 0で貼ることのできる辺を処理する
for i in range(l, r + 1):
    j = 2 * i
    while j < r + 1:
        if unite(i - l, j - l):
            cnt += 1
        j += i
print(r - l + -cnt)
0