結果
問題 | No.1059 素敵な集合 |
ユーザー | wolgnik |
提出日時 | 2020-05-22 21:53:26 |
言語 | PyPy3 (7.3.13) |
結果 |
AC
|
実行時間 | 154 ms / 2,000 ms |
コード長 | 994 bytes |
コンパイル時間 | 259 ms |
コンパイル使用メモリ | 87,160 KB |
実行使用メモリ | 94,008 KB |
最終ジャッジ日時 | 2023-09-30 15:27:57 |
合計ジャッジ時間 | 3,919 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge12 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 71 ms
71,448 KB |
testcase_01 | AC | 129 ms
80,348 KB |
testcase_02 | AC | 144 ms
80,872 KB |
testcase_03 | AC | 75 ms
71,332 KB |
testcase_04 | AC | 71 ms
71,140 KB |
testcase_05 | AC | 72 ms
71,628 KB |
testcase_06 | AC | 134 ms
78,588 KB |
testcase_07 | AC | 134 ms
78,776 KB |
testcase_08 | AC | 137 ms
79,676 KB |
testcase_09 | AC | 125 ms
78,488 KB |
testcase_10 | AC | 132 ms
78,744 KB |
testcase_11 | AC | 134 ms
79,088 KB |
testcase_12 | AC | 153 ms
79,120 KB |
testcase_13 | AC | 139 ms
80,916 KB |
testcase_14 | AC | 84 ms
77,000 KB |
testcase_15 | AC | 147 ms
82,432 KB |
testcase_16 | AC | 137 ms
79,328 KB |
testcase_17 | AC | 139 ms
79,912 KB |
testcase_18 | AC | 90 ms
94,008 KB |
testcase_19 | AC | 142 ms
80,776 KB |
testcase_20 | AC | 154 ms
81,472 KB |
testcase_21 | AC | 154 ms
83,760 KB |
ソースコード
import sys input = sys.stdin.readline L, R = map(int, input().split()) class UnionFind(): def __init__(self, n): self.n = n self.root = [-1] * (n + 1) self.rnk = [0] * (n + 1) def Find_Root(self, x): if self.root[x] < 0: return x else: self.root[x] = self.Find_Root(self.root[x]) return self.root[x] def Unite(self, x, y): x = self.Find_Root(x) y = self.Find_Root(y) if x == y: return elif self.rnk[x] > self.rnk[y]: self.root[x] += self.root[y] self.root[y] = x else: self.root[y] += self.root[x] self.root[x] = y if self.rnk[x] == self.rnk[y]: self.rnk[y] += 1 def isSameGroup(self, x, y): return self.Find_Root(x) == self.Find_Root(y) def Count(self, x): return -self.root[self.Find_Root(x)] uf = UnionFind(R) for x in range(L, R + 1): for y in range(2 * x, R + 1, x): uf.Unite(x, y) s = set() for x in range(L, R + 1): s.add(uf.Find_Root(x)) print(len(s) - 1)