結果
| 問題 | No.1059 素敵な集合 |
| コンテスト | |
| ユーザー |
convexineq
|
| 提出日時 | 2020-05-22 21:34:37 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
AC
|
| 実行時間 | 1,090 ms / 2,000 ms |
| コード長 | 1,260 bytes |
| コンパイル時間 | 85 ms |
| コンパイル使用メモリ | 12,928 KB |
| 実行使用メモリ | 20,096 KB |
| 最終ジャッジ日時 | 2024-10-05 15:53:22 |
| 合計ジャッジ時間 | 6,485 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 19 |
ソースコード
class UnionFind:
def __init__(self, n):
self.parent = list(range(n)) #親ノード
self.size = [1]*n #グループの要素数
def root(self, x): #root(x): xの根ノードを返す.
while self.parent[x] != x:
self.parent[x] = self.parent[self.parent[x]]
x = self.parent[x]
return x
def merge(self, x, y): #merge(x,y): xのいる組とyのいる組をまとめる
x, y = self.root(x), self.root(y)
if x == y: return False
if self.size[x] < self.size[y]: x,y=y,x #xの要素数が大きいように
self.size[x] += self.size[y] #xの要素数を更新
self.parent[y] = x #yをxにつなぐ
return True
def issame(self, x, y): #same(x,y): xとyが同じ組ならTrue
return self.root(x) == self.root(y)
def getsize(self,x): #size(x): xのいるグループの要素数を返す
return self.size[self.root(x)]
# coding: utf-8
# Your code here!
import sys
readline = sys.stdin.readline
read = sys.stdin.read
l,r = [int(i) for i in readline().split()]
UF = UnionFind(r+1)
res = r-l+1
for i in range(l,r+1):
for j in range(i+i,r+1,i):
if UF.merge(i,j):
res -= 1
print(res-1)
convexineq