結果
| 問題 |
No.1059 素敵な集合
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-05-22 21:46:11 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 14 ms / 2,000 ms |
| コード長 | 1,320 bytes |
| コンパイル時間 | 1,121 ms |
| コンパイル使用メモリ | 99,472 KB |
| 最終ジャッジ日時 | 2025-01-10 14:37:20 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 19 |
ソースコード
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>
static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;
template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;
class UnionFind {
int n;
vector<int> uni;
int forest_size;
public:
explicit UnionFind(int n) : n(n), uni(static_cast<u32>(n), -1), forest_size(n) {};
int root(int a){
if (uni[a] < 0) return a;
else return (uni[a] = root(uni[a]));
}
bool unite(int a, int b) {
a = root(a);
b = root(b);
if(a == b) return false;
if(uni[a] > uni[b]) swap(a, b);
uni[a] += uni[b];
uni[b] = a;
forest_size--;
return true;
}
int size(){ return forest_size; }
int size(int i){ return -uni[root(i)]; }
bool same(int a, int b) { return root(a) == root(b); }
};
int main() {
int l, r;
cin >> l >> r;
vector<int> v(r+1, 1);
UnionFind uf(r-l+1);
int ans = 0;
for (int i = l; i <= r; ++i) {
for (int j = i+i; j <= r; j += i) {
uf.unite(i-l, j-l);
}
}
cout << uf.size()-1 << "\n";
return 0;
}