結果

問題 No.1059 素敵な集合
ユーザー nephrologistnephrologist
提出日時 2020-05-22 23:42:47
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 1,649 ms / 2,000 ms
コード長 889 bytes
コンパイル時間 93 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 14,720 KB
最終ジャッジ日時 2024-04-15 19:18:45
合計ジャッジ時間 8,216 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 28 ms
10,880 KB
testcase_01 AC 1,649 ms
12,288 KB
testcase_02 AC 139 ms
12,544 KB
testcase_03 AC 29 ms
10,752 KB
testcase_04 AC 28 ms
10,880 KB
testcase_05 AC 28 ms
10,752 KB
testcase_06 AC 117 ms
11,904 KB
testcase_07 AC 117 ms
11,776 KB
testcase_08 AC 160 ms
12,288 KB
testcase_09 AC 48 ms
11,264 KB
testcase_10 AC 283 ms
12,672 KB
testcase_11 AC 134 ms
11,904 KB
testcase_12 AC 73 ms
11,392 KB
testcase_13 AC 273 ms
13,056 KB
testcase_14 AC 30 ms
10,752 KB
testcase_15 AC 544 ms
14,592 KB
testcase_16 AC 144 ms
12,032 KB
testcase_17 AC 130 ms
12,160 KB
testcase_18 AC 55 ms
11,520 KB
testcase_19 AC 1,465 ms
12,288 KB
testcase_20 AC 1,438 ms
12,416 KB
testcase_21 AC 483 ms
14,720 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