結果
問題 | No.1059 素敵な集合 |
ユーザー |
![]() |
提出日時 | 2020-05-22 22:44:33 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 16 ms / 2,000 ms |
コード長 | 845 bytes |
コンパイル時間 | 2,282 ms |
コンパイル使用メモリ | 193,500 KB |
最終ジャッジ日時 | 2025-01-10 14:58:36 |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 19 |
ソースコード
#include <bits/stdc++.h> using namespace std; #ifdef LOCAL #include "debug.h" #else #define DEBUG(...) #endif struct dsu { int cc; vector<int> p, sz; dsu(int n = 0) : cc(n), p(n, -1), sz(n, 1) {} int root(int v) const { while (p[v] != -1) v = p[v]; return v; } bool unite(int u, int v) { u = root(u), v = root(v); if (u == v) return false; --cc; if (sz[u] < sz[v]) swap(u, v); p[v] = u; sz[u] += sz[v]; return true; } bool same(int u, int v) const { return root(u) == root(v); } int size(int v) const { return sz[root(v)]; } }; int main() { cin.tie(nullptr); ios::sync_with_stdio(false); int l, r; cin >> l >> r; dsu ds(r - l + 1); for (int d = l; d <= r; ++d) { for (int i = 2 * d; i <= r; i += d) { ds.unite(d - l, i - l); } } cout << ds.cc - 1 << '\n'; }