結果
問題 | No.1059 素敵な集合 |
ユーザー |
![]() |
提出日時 | 2020-05-22 23:55:00 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 11 ms / 2,000 ms |
コード長 | 1,254 bytes |
コンパイル時間 | 1,014 ms |
コンパイル使用メモリ | 106,288 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-07-23 09:35:09 |
合計ジャッジ時間 | 1,771 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 19 |
ソースコード
#include <functional> #include <algorithm> #include <iostream> #include <iomanip> #include <cstring> #include <string> #include <vector> #include <random> #include <bitset> #include <queue> #include <cmath> #include <stack> #include <set> #include <map> typedef long long ll; using namespace std; const ll MOD = 1000000007LL; class UnionFind { vector<int> par; int n; public: UnionFind(int sz) : par(sz, -1) {} int find(int x) { if (par[x] < 0) return x; return par[x] = find(par[x]); } bool unite(int x, int y) { x = find(x); y = find(y); if (x == y) return false; if (par[x] > par[y]) swap(x, y); par[x] += par[y]; par[y] = x; return true; } bool same(int x, int y) { return find(x) == find(y); } int size(int x) { return -par[find(x)]; } }; int main() { int l, r; cin >> l >> r; UnionFind uf(r - l + 1); for (int i = l; i <= r; i++) { for (int j = 2; i * j <= r; j++) { uf.unite(i - l, i * j - l); } } int ans = -1; for (int i = l; i <= r; i++) { if (uf.find(i - l) == i - l) { ans++; } } cout << ans << endl; return 0; }