結果
問題 | No.1059 素敵な集合 |
ユーザー | 👑 tamato |
提出日時 | 2020-05-22 21:46:19 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 494 ms / 2,000 ms |
コード長 | 1,376 bytes |
コンパイル時間 | 314 ms |
コンパイル使用メモリ | 87,432 KB |
実行使用メモリ | 80,640 KB |
最終ジャッジ日時 | 2023-09-30 15:27:14 |
合計ジャッジ時間 | 4,907 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge12 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 74 ms
71,772 KB |
testcase_01 | AC | 74 ms
71,456 KB |
testcase_02 | AC | 138 ms
78,608 KB |
testcase_03 | AC | 71 ms
71,400 KB |
testcase_04 | AC | 72 ms
71,284 KB |
testcase_05 | AC | 72 ms
71,680 KB |
testcase_06 | AC | 131 ms
78,604 KB |
testcase_07 | AC | 130 ms
78,824 KB |
testcase_08 | AC | 143 ms
78,768 KB |
testcase_09 | AC | 117 ms
78,116 KB |
testcase_10 | AC | 191 ms
79,120 KB |
testcase_11 | AC | 139 ms
78,672 KB |
testcase_12 | AC | 120 ms
78,144 KB |
testcase_13 | AC | 177 ms
79,480 KB |
testcase_14 | AC | 85 ms
76,720 KB |
testcase_15 | AC | 257 ms
80,464 KB |
testcase_16 | AC | 139 ms
78,616 KB |
testcase_17 | AC | 133 ms
78,768 KB |
testcase_18 | AC | 79 ms
79,056 KB |
testcase_19 | AC | 473 ms
80,392 KB |
testcase_20 | AC | 494 ms
80,640 KB |
testcase_21 | AC | 242 ms
80,252 KB |
ソースコード
mod = 1000000007 eps = 10**-9 def main(): import sys input = sys.stdin.readline class UnionFind(): def __init__(self, n): self.n = n self.root = [-1] * (n + 1) self.rnk = [0] * (n + 1) def find_root(self, x): while self.root[x] >= 0: x = self.root[x] return 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 size(self, x): return -self.root[self.find_root(x)] L, R = map(int, input().split()) if L == 1: print(0) exit() UF = UnionFind(R+1) ans = R - L for d in range(L, R+1): for j in range(2, R+1): if d*j > R: break if not UF.isSameGroup(d, d*j): ans -= 1 UF.unite(d, d*j) print(ans) if __name__ == '__main__': main()