結果

問題 No.1059 素敵な集合
ユーザー anagohirameanagohirame
提出日時 2020-05-22 23:43:22
言語 PyPy3
(7.3.15)
結果
MLE  
実行時間 -
コード長 849 bytes
コンパイル時間 312 ms
コンパイル使用メモリ 82,144 KB
実行使用メモリ 652,536 KB
最終ジャッジ日時 2024-04-15 19:19:15
合計ジャッジ時間 4,365 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
53,300 KB
testcase_01 MLE -
testcase_02 AC 167 ms
79,316 KB
testcase_03 AC 35 ms
53,184 KB
testcase_04 AC 33 ms
53,920 KB
testcase_05 AC 35 ms
52,836 KB
testcase_06 AC 120 ms
77,568 KB
testcase_07 AC 123 ms
77,972 KB
testcase_08 AC 154 ms
78,420 KB
testcase_09 AC 131 ms
78,492 KB
testcase_10 AC 177 ms
77,572 KB
testcase_11 AC 132 ms
78,056 KB
testcase_12 AC 121 ms
77,772 KB
testcase_13 AC 162 ms
79,296 KB
testcase_14 AC 50 ms
65,764 KB
testcase_15 AC 229 ms
79,624 KB
testcase_16 AC 121 ms
77,776 KB
testcase_17 AC 146 ms
78,820 KB
testcase_18 AC 46 ms
62,888 KB
testcase_19 AC 1,250 ms
364,904 KB
testcase_20 AC 920 ms
267,324 KB
testcase_21 AC 237 ms
80,048 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
sys.setrecursionlimit(10**6)

class UnionFind():
	def __init__(self, size):
		self.table = [-1 for _ in range(size)]
		self.size = [1 for _ in range(size)]

	def find(self, x):
		if self.table[x] < 0:
			return x
		else:
			self.table[x] = self.find(self.table[x])
			return self.table[x]

	def unite(self, x, y):
		s1 = self.find(x)
		s2 = self.find(y)
		if s1 != s2:
			if self.table[s1] > self.table[s2]:
				self.table[s2] = s1
				self.table[s1] -= 1
				self.size[s1] += self.size[s2]
				self.size[s2] = 0
			else:
				self.table[s1] = s2
				self.table[s2] -= 1
				self.size[s2] += self.size[s1]
				self.size[s1] = 0

		return

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)

ans = -1
for i in range(l, r+1):
	if uf.table[i] < 0:
		ans += 1
print(ans)
0