結果
問題 | No.1059 素敵な集合 |
ユーザー | rlangevin |
提出日時 | 2023-06-27 12:18:12 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 193 ms / 2,000 ms |
コード長 | 1,050 bytes |
コンパイル時間 | 1,103 ms |
コンパイル使用メモリ | 87,168 KB |
実行使用メモリ | 93,148 KB |
最終ジャッジ日時 | 2023-09-17 09:25:31 |
合計ジャッジ時間 | 5,077 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge13 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 73 ms
71,284 KB |
testcase_01 | AC | 120 ms
81,872 KB |
testcase_02 | AC | 153 ms
80,984 KB |
testcase_03 | AC | 73 ms
71,044 KB |
testcase_04 | AC | 71 ms
71,264 KB |
testcase_05 | AC | 72 ms
71,188 KB |
testcase_06 | AC | 143 ms
79,068 KB |
testcase_07 | AC | 141 ms
78,692 KB |
testcase_08 | AC | 143 ms
80,336 KB |
testcase_09 | AC | 136 ms
77,788 KB |
testcase_10 | AC | 141 ms
79,724 KB |
testcase_11 | AC | 139 ms
79,012 KB |
testcase_12 | AC | 151 ms
79,524 KB |
testcase_13 | AC | 151 ms
81,304 KB |
testcase_14 | AC | 88 ms
76,284 KB |
testcase_15 | AC | 163 ms
83,624 KB |
testcase_16 | AC | 141 ms
79,504 KB |
testcase_17 | AC | 147 ms
80,816 KB |
testcase_18 | AC | 96 ms
93,148 KB |
testcase_19 | AC | 157 ms
81,976 KB |
testcase_20 | AC | 193 ms
83,044 KB |
testcase_21 | AC | 166 ms
84,712 KB |
ソースコード
class UnionFind(object): def __init__(self, n=1): self.par = [i for i in range(n)] self.rank = [0 for _ in range(n)] self.size = [1 for _ in range(n)] def find(self, x): if self.par[x] == x: return x else: self.par[x] = self.find(self.par[x]) return self.par[x] def union(self, x, y): x = self.find(x) y = self.find(y) if x != y: if self.rank[x] < self.rank[y]: x, y = y, x if self.rank[x] == self.rank[y]: self.rank[x] += 1 self.par[y] = x self.size[x] += self.size[y] def is_same(self, x, y): return self.find(x) == self.find(y) def get_size(self, x): x = self.find(x) return self.size[x] L, R = map(int, input().split()) U = UnionFind(R - L + 1) for i in range(L, R + 1): for j in range(2 * i, R + 1, i): U.union(i - L, j - L) S = set() for i in range(R - L + 1): S.add(U.find(i)) print(len(S) - 1)