結果
問題 | No.1059 素敵な集合 |
ユーザー | H3PO4 |
提出日時 | 2021-10-05 09:14:32 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 175 ms / 2,000 ms |
コード長 | 1,352 bytes |
コンパイル時間 | 312 ms |
コンパイル使用メモリ | 87,040 KB |
実行使用メモリ | 94,540 KB |
最終ジャッジ日時 | 2023-09-30 08:28:16 |
合計ジャッジ時間 | 4,206 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge11 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 71 ms
71,372 KB |
testcase_01 | AC | 119 ms
81,752 KB |
testcase_02 | AC | 140 ms
79,876 KB |
testcase_03 | AC | 71 ms
71,592 KB |
testcase_04 | AC | 72 ms
71,376 KB |
testcase_05 | AC | 75 ms
71,220 KB |
testcase_06 | AC | 133 ms
79,400 KB |
testcase_07 | AC | 131 ms
79,008 KB |
testcase_08 | AC | 139 ms
79,944 KB |
testcase_09 | AC | 128 ms
78,336 KB |
testcase_10 | AC | 130 ms
79,088 KB |
testcase_11 | AC | 134 ms
79,008 KB |
testcase_12 | AC | 148 ms
79,056 KB |
testcase_13 | AC | 138 ms
80,552 KB |
testcase_14 | AC | 83 ms
76,680 KB |
testcase_15 | AC | 148 ms
81,812 KB |
testcase_16 | AC | 133 ms
79,068 KB |
testcase_17 | AC | 140 ms
79,808 KB |
testcase_18 | AC | 89 ms
94,540 KB |
testcase_19 | AC | 146 ms
82,080 KB |
testcase_20 | AC | 175 ms
82,060 KB |
testcase_21 | AC | 151 ms
82,752 KB |
ソースコード
class UnionFind: def __init__(self, n): self.n = n self.parent = [i for i in range(n)] self.height = [1] * n self.size = [1] * n def find(self, x): if self.parent[x] == x: return x else: self.parent[x] = self.find(self.parent[x]) return self.parent[x] def unite(self, x, y): x = self.find(x) y = self.find(y) if x != y: if self.height[x] < self.height[y]: self.parent[x] = y self.size[y] += self.size[x] else: self.parent[y] = x self.size[x] += self.size[y] if self.height[x] == self.height[y]: self.height[x] += 1 def issame(self, x, y): return self.find(x) == self.find(y) def group_size(self, x): return self.size[self.find(x)] def group_members(self, x): root = self.find(x) return [i for i in range(self.n) if self.find(i) == root] def roots(self): return [i for i, x in enumerate(self.parent) if i == x] def group_count(self): return len(self.roots()) L, R = map(int, input().split()) uf = UnionFind(R + 1) for i in range(L, R + 1): for j in range(i * 2, R + 1, i): uf.unite(i, j) print(uf.group_count() - L - 1)